Wednesday, July 10, 2013

Re: DJANGOֹ_SETTINGS_MODULE different from folder name

It's all about sys.path and the semantics of import.

DJANGO_SETTINGS_MODULE must be a name that can be imported.  Any dots in the string divide the name into a number of names.  The first name must be findable via sys.path.  If it is the last name, it can name a .py file.  Otherwise it must be the name of a package, that is, a directory (folder) containing an __init__.py file, as well as the next name in the chain as a package, or if it is the last name, it can be a .py file.

The lookup for the root urlconf, etc, and any installed apps that are under your project directory, as opposed to installed in your site-packages or dist-packages directories.  You have to fix them all.

I have often played with things like os.path.dirname(os.path.abspath(__file__)) to discover the prefix to use in ROOT_URLCONF, etc.

You don't mention what Django version you are using.  The more modern Djangos have much less trouble with this stuff, where the structure, as created by startproject, usually involves something like myproject/myproject/settings.py and you can rename the first of the myproject directories as you like.  You must still arrange for it to be on your sys.path, however.  When using manage.py runserver, this is automatic, because we cd to that directory before running the command, and the current directory is added to sys.path by default.  Apache's WSGI, however, has required (there is something new in the works) that you specify that directory somehow.


Separately, why is your project under /var/www ?  Not only is it not required to be there, it also really shouldn't be there.  You don't want Apache serving your source code.

Bill


On Wed, Jul 10, 2013 at 2:39 AM, Etay Cohen-Solal <et.std8@gmail.com> wrote:
It's kinda noob question, 
but I have a working dev project inside directory
/var/www/django/myproject
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'

I want to change the folder of the project to something like:
/var/www/websites/il_co_project_name_www

but i get 500 Internal Server Error.

If I change the DJANGO_SETTINGS_MODULE to:
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
(remove the myproject.)
Then WSGI works, but I get Django errors of missing URL conf, and then VIEW, etc...
can I use DJANGO_SETTINGS_MODULE different from folder name?

--
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate