Monday, September 24, 2018

Running a single version of my Django app but with two databases: one for dev and one for prod

Hi, 

I'm developing a Django app, it's hosted on an EC2 instance so I'm using wsgi, even in development. I would like to create a production and a development version where really the only things that are different are the two databases. I want the code to be the same on both. I figured I could just have two settings files and two wsgi.py files so it's set up like this:

wsgi_prod.py:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "canzare.settings.production")

application = get_wsgi_application()


wsgi_dev.py:


import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "canzare.settings.development")

application = get_wsgi_application()


Then in my httpd.conf I have these lines:


WSGIScriptAlias /dev /home/canzare/work_area/canzare/canzare/wsgi_dev.py

WSGIScriptAlias / /home/canzare/work_area/canzare/canzare/wsgi_prod.py


The only real difference in the settings.py files is that they point to two different databases in mysql. 


This sort of works, I can access the production site with <mysite>/ and I can access the development site with <mysite>/dev/


But then everything falls apart. The admin site on both seems to be broken. It looks ok but if I try to perform any actions it tries to make me re-login. 


Also (and this may be the root of the other problem) I don't think migration works correctly. I can migrate to one instance but not the other. 


Has anybody come across something like this before and/or and I'm going about this completely wrong and is there a better way?


Thanks. 

Jim



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/74e03d03-e47e-47aa-bd96-62519068026c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment