Summary:
Say I have a project in Django called "devsite" which will be deployed first to a staging project (also called "devsite") and finally to the live codebase (where the project is called "livesite"). During live deployments, I'd have to make manual changes to urls.py in order to import views from the right project. Which means urls.py in "devsite" would use something like:
from devsite import views
And urls.py for "livesite" would be changed to:
from livesite import views
My Solution:
The following seems to work (with limited testing so far). What I've done is create a variable in settings.py to get the project name from the directory, like so:
settings.py
# /settings.py
import os.path
PROJECT_NAME = os.path.basename(os.path.dirname(__file__))
And then use this to import the correct views in urls.py:
urls.py
# /urls.py
from django.conf import settings
website = __import__('%s' % settings.PROJECT_NAME, fromlist=['views'])
...
urlpatterns = patterns('',
(r'^monty/$', website.views.monty),
)
My Question:
What I'd like to know is:
- Is this a good way of doing what I want to do, or is there a better way to code this?
- Or do I need to rethink my whole deployment workflow?
Thanks in advance.