https://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/
Where would i add this?
path = '/path/to/mysite' if path no开发者_开发技巧t in sys.path: sys.path.append(path)
You should create a file django.wsgi and put that line there. In m case, django.wsgi contains,
import os
import sys
sys.path.append('H:/Projectys/mysite')
sys.path.append('H:/Projects/mysite/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I have added sys.path such that because my project tree is
+H
++Projects
+++mysite
++++mysite
+++++apache
++++++django.wsgi
+++++mysite
++++++setting.py
++++++__init__.py
++++++urls.py
++++++view.py
+++++media
You should reference the location of django.wsgi
in your httpd.conf
(apache conf)
FWIW, you should also read the official mod_wsgi documentation as well.
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
Technically it doesn't matter where in the file you place the lines adding extra directories to sys.path if they are only referring to where your Django site directory it. This is because they only need to be set up by the time the first web request occurs. That is, the first time the application object is called.
So, if you stuck them as the very last thing in the file it would actually still work. In general though, it looks more logical to stick them in before you actually import Django modules. By doing that you ensure that if Django were ever changed to do loading up front rather than lazy loading on first request that it will still work.
Obviously they at least have to be after the import of 'sys' though.
Just after this code, it is written :
just below the import sys line to place your project on the path. Remember to replace 'mysite.settings' with your correct settings file, and '/path/to/mysite' with your own project's location.
精彩评论