how do i setup django in wamp? - python

I want to test my django app in my WAMP server. The idea is that i want to create a web app for aaa.com and aaa.co.uk, if the user enter the domain aaa.co.uk, my django app will serve the UK version, if the user go to aaa.com, the same django app will serve the US version (different frontend). Basically i will be detecting the host of the user and serve the correct templates.
How do i setup my WAMP so i can test this? right now i am using pyCharm default server which is 127.0.0.1:8000

Ok the answer is basically ericeastwood.com/blog/3/django-setup-for-wamp combined with httpd.apache.org/docs/2.4/vhosts/name-based.html – shadow

first install mysqliclient module using below command
pip install mysqlclient
open settings.py file and change database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'yourdbname',
'USER': 'dbusername',
'PASSWORD': 'your password',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}

Related

django - use environment variables in debian not working

It might be simple thing but I just can't seem to get it running.
in my Django project's settings, I have these db settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER'),
'PASSWORD': os.getenv('DB_PWD'),
'HOST': 'xxxx.yyyyy.eu-central-1.rds.amazonaws.com',
'PORT': '',
}
}
and in /etc/environment I have set the variables and also in .profile.
but this is just not working and I am getting:
(1045, "Access denied for user 'www-data'#'132.31.48.116' (using password: NO)")
If I remove and hardcode the credentials, it works. so obviously my env variables are located in wrong place. can someone please give some look at it?
I am using Debian 4.9.51-1 (2017-09-28) x86_64 in ec2 server

Django:permission denied for relation django_migrations, PostgreSql - django user?

I ve been struggling about figuring out relation between postgre users and linux users and the permissions between them.First question I want to ask is that ,let s assume I have tom linux user and tom postgre user which I created with psql command.What is the relation between those two? The reason I am asking is realated with following question:
I am using vagrant and ubuntu in it.There is 2 userss , first one is Linux "vagrant" user , second one is PostgreSql "vagrant" user which I created through following commands:
CREATE USER vagrant WITH PASSWORD '123.123';
GRANT ALL PRIVILEGES ON DATABASE cashier to vagrant;
which should means and also is that vagrant have all permissions on cashier database.
I should also mention as an aside note that I am using provisioning and vagrant uses root user when executing provisions , so root should also have all permissions on the cashier databse because I am importing dump into cashier database on provisioning.
so you can easily assume root have granted permissions through :
CREATE USER root WITH PASSWORD 'vagrant';
GRANT ALL PRIVILEGES ON DATABASE cashier to root;
Here is the problem: When I try to runserver in django python manage.py runserver
if I go with the following settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'cashier',
'USER': 'vagrant',
'PASSWORD': '123.123',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
I get authentication error, and if I go with the following settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'cashier',
'USER': 'vagrant',
'PASSWORD': 'vagrant',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Then i have Django:permission denied for relation django_migrations, problem.Simply my question is What is going on?What is the relation between users?Which user should i use ? Why django cant migrate with both user credentials?
Recall :
Linux user vagrant pass vagrant
Postgre user vagrant pass 123.123

How to work on the same django project on two different machines?

I have my Django project all saved in a virtual environment, and I'm using PostgreSQL. When I copied my virtual environment onto a second PC, I can not launch the project because of database authentication problems. I'm just wondering if it is possible to duplicate the project (with database) onto a second machine, and work on the development from two machines. Thanks in advance!
You need to create database with all of your credentials that located in settings.py file. And if you want, copy data from db on the first computer with pg_dump and then put that data on newly created database.
This is a very common situation. You could use multiple setting files to achieve this.
Let's say your project is myproject:
so in myproject/ you have:
- __init__.py
- urls.py
- wsgi.py
- settings.py
You could add a new file with your local configuration:
- local_settings.py
You can override database configuration in this file:
DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'newdatabase',
'USER': 'newuser',
'PASSWORD': 'newpassword',
'HOST': '127.0.0.1', # Or an IP Address that your DB is hosted on
# 'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
Then, add at the end of your original settings.py file:
try:
from .local_settings import *
except ImportError:
pass
Everywhere you carry your project you can create a new local_settings.py file with any new config you need.
Remember you can ignore this file (local_settings.py) in your github repository, so when you clone you project in a new PC you will just need to create a new local_settings.py and make you project run.

About Database Settings in Django Project

I want to set database setting in django project.
Which settings.py I should use.
I found many settings.py file.
I have setup devstack where many folders are there like horizon, cinder, nova etc.
I found settings.py in horizon folder.
and from when I setup Django I found in /usr/local/lib/python2.7/dist-packages/django/conf/project_template/project_name folder.
Please make suggest which settings.py I should use and
I can access database by user root with no database name giving in MySql Workbench.
Which database connection I should use?
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'nova',
'USER': 'root',
'PASSWORD': 'password',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
Please help..
You have to setup your DB in the settings.py file in horizon/openstack_dashboard folder .The DB name is devstack or any other name .All the django apps table will be created in a single DB

how do I confirm django is working with xampp's mysql

I am starting to learn django , and I'm trying to set up a development environment as in http://www.venkysblog.com/setup-django-on-windows-with-apache-and-mysql. I'm having trouble getting it working and so I'm working backwards to make sure I have it all correct.
I'm ok up to step 4. I have confirmed python , xampp and django working . I have created a DB called django using phpmyadmin
I have a project called testproject, with the settings.py file including:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'post
'NAME': 'django', # Or path to database file if usi
'USER': 'root', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. No
'PORT': '', # Set to empty string for default. Not
}
}
when I run $ python manage.py runserver I get:
Validating models...
0 errors found
Django version 1.4.3, using settings 'testproject.settings'
Development server is running at htp://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Is there an explicit way to test the connection to 'django' db at this point?
Thanks in advance,
Bill
If you do manage.py syncdb it'll try to create your tables, and you'll know if it succeeded or failed.

Categories