0

I have a Django project which was deployed on a staging server under Apache2 and mod_wsgi, and it was working fine. It uses the django-registration application.

I tried to switch my server over to nginx and to run the Django project with gunicorn. The project was loaded up fine, except when I tried to reach /admin and /user/logout (default is /account with django-registration) it would give me a "No module named urls" error. I tore my hair out for hours. I commented out the registration url line in urls.py and then admin showed up fine, except it was missing the registration models. So admin was only failing because registration was failing.

Ideally I'd like to push out my project into production using the nginx/gunicorn setup, but registration doesn't seem to want to play nicely. I tried removing registration, installing 0.8 from source, removing that, pip installing 0.7, nothing worked. What worked was stopping nginx and then running apache again. So essentially, the project is untouched save for the type of web server being used.

Since registration seems to be working fine under Apache/mod_wsgi, I'm tempted to just push to production with that setup... but I'm still curious to know why registration just won't work with gunicorn when I try. Any help would be appreciated.

xtine
  • 2,599
  • 2
  • 18
  • 15
  • did you check this xtine [gunicorn and django project (no app)](http://stackoverflow.com/questions/5375861/gunicorn-and-django-project-no-app)?this might be a reason for "No module named urls". check this it might be helpful [Deploying Django project with gunicorn and Nginx](http://www.rkblog.rk.edu.pl/w/p/deploying-django-project-gunicorn-and-nginx/) – Bastardo May 25 '11 at 07:06

1 Answers1

1

Sounds like your sys.path is setup differently when using mod_wsgi. It's a pretty common mistake to run into when deploying so a good first step would be checking your sys.path when running gunicorn. Are you using virtualenv? Make sure to install gunicorn into your virtualenv as well as django-registration and any other dependencies you might have. If you run the gunicorn script in your virtualenv's bin dir everything should just work.

Zach Kelling
  • 52,505
  • 13
  • 109
  • 108
  • I thought it was a PYTHONPATH issue so in the project folder where I launch gunicorn, I exported the path to dist-packages to see if it would work. In the TemplateError page it seemed to be going through all the correct python folders correctly. I haven't tried virtualenv yet, that is something I will probably try next. – xtine May 25 '11 at 16:03
  • I always use (and recommend) [distribute](http://pypi.python.org/pypi/distribute) & [pip](http://www.pip-installer.org/en/latest/) with virtualenv. Give that a shot and see if it helps alleviate your deployment woes. It's a good idea in general, since you can isolate your various projects and avoid dependency conflicts, etc. – Zach Kelling May 25 '11 at 16:16
  • [Here's a useful crash course.](http://www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django/) – Zach Kelling May 25 '11 at 16:22
  • I was able to get django-registration working with nginx+gunicorn under a different server. I don't necessarily have time to work under the hood to really figure out the culprit, so I will probably wipe the server and try again, and this time with virtualenv moving forward. :) – xtine Jun 02 '11 at 18:29
  • Any help? http://stackoverflow.com/questions/8823164/run-gunicorn-works-but-not-gunicorn-django-despite-both-within-the-same-environm – Mickey Cheong Jan 11 '12 at 16:48