1

https://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

Where would i add this?

path = '/path/to/mysite' if path not in sys.path: sys.path.append(path)

3 Answers 3

2

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)

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.