Primary image for Managing Django Projects on Your Server with Style

Managing Django Projects on Your Server with Style

This article is outdated, you’ll find an updated article here.

A friend is in the process of setting up a new slice at everbody’s favorite VPS provider Slicehost and asked for some advice. I use MySQL, Nginx & Apache/mod_wsgi on Ubuntu to serve Django. I think Slicehost’s Articles are awesome and a great place to get help you get everything installed and running, so for this article, I’ll focus on some personal preferences regarding directory structure and repo management.

One of the biggest difficulties I’ve had to tackle lately is the rapid progress of Django. I have a number of client sites hosted on my slice and have had to freeze them at certain times when backwards incompatible changes come along. My original approach made this really messy, because I only accounted for having one copy of any given third party repo, symlinked from /usr/local/src to my Python site-packages directory. My new approach takes advantage of being able to set your PYTHONPATH at runtime.

My directory structure looks like this:

|-django
|--projects
|---domain1.com
|---domain2.com
|---domain3.com
Each site has the following structure:
|-domain1.com
|--apache
|---django.wsgi
|--django
|--domain1_project
|---__init__.py
|---app1
|---app2
|---manage.py
|---settings.py
|---static
|---templates
|---urls.py
|--third_party_repo1
|--third_party_repo2
Just drop domain1.com in your PYTHONPATH and you’re good to go. I usually start with django and the third party repos as symlinks to a current checkout of the code in /usr/local/src. When the project is completed or if the linked code passes us by, I simply replace the symlink with an actual copy of the repo. This gives me a nice compartmentalized folder of the project that would be easy to move if needed. I can also update my repos in /usr/local/src without worrying about which project might break from the new code. Have a better way to do things? Leave a comment and let me know. Thanks for reading and tune in next week to really geek out with Nginx & Apache/mod_wsgi configuration files.
Peter Baumgartner

About the author

Peter Baumgartner

Peter is the founder of Lincoln Loop, having built it up from a small freelance operation in 2007 to what it is today. He is constantly learning and is well-versed in many technical disciplines including devops, …

View Peter's profile