views:

152

answers:

3

I seem to have run into a bit of an issue.

I am busy creating an app, and over the last few weeks setup my server to use Git, mod_wsgi to host this app.

Since deploying it, everything seems to be running smoothly however, I had to go through all my files and insert the absolute url of the project to make sure it works fine.

on my local machine

from registration.models import UserRegistration

on server

from myapp.registration.models import UserRegistration

Am I doing something wrong?

And this has also caused an issue for me where I cannot access my django admin interface.

All i get is this: Caught an exception while rendering: No module named registration

Exception Value: Caught an exception while rendering: No module named registration

As far as I am concerned my app has all the relevant urls, but it does not seem to work.

Thank you in advance

A: 

myapp.registration.models is the correct way of importing. You should think of your entire Django website as one Python package named myapp rather than using a bunch of relative intra-package imports like registration.models, which as you can see break under certain HTTP environments, like mod_wsgi's. What you should do now is go through your entire web application and start using the myapp. prefix, which should completely fix the problems you're having with mod_wsgi if everything else is set up correctly. You might have to alter your development environment a little, of course, but it'll be for the Greater Pythonic Good.

Hao Lian
No, absolutely not. There is no reason to do this, especially for example if `registration` is a third-party Django app. You just need to set up your python path correctly.
Daniel Roseman
thanks for the help, so basically if the python paths are setup correctly then it should eliminate all exception errors caught?
ApPeL
THANK YOU SO MUCH!!! it works
ApPeL
Daniel, yes you can leave them off, but that you can highlights a poor design issue within Django. That is that it is possible to import parts of the site by two different module import names. This can cause problems with double imports. Ultimately as long as you are consistent and use one method or the other then you will generally be okay, but a package view of an site really says that the site prefix should be used. If you aren't going to view it as a whole package, move apps outside the site. Read 'http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html'.
Graham Dumpleton
A: 

The problem is occurring because somehow your local machine is adding the myapp directory to the PYTHONPATH, as well as its parent directory. The way to fix this is to modify your .wsgi script to add both these directories to sys.path:

import sys
sys.path.insert(0, '/path/to/parent')
sys.path.insert(0, '/path/to/parent/myapp')
Daniel Roseman
+1  A: 

Read and use improved WSGI script in:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

This will set up environment to better match Django built in development server and you shoud hopefully not see a difference between the two, especially in respect of how Python module search path is handled.

Graham Dumpleton