I have deployed a Django project on an Apache server using mod_wsgi, using a prefix URL /mysite
, i.e. my Apache configuration contains
WSGIScriptAlias /mysite /var/www/mysite/mysite/wsgi.py
When reverse('myview')
(from django.core.urlresolvers
) is called from the web server process, it returns the expected URL /mysite/myview
, i.e. including the prefix URL.
However, when reverse('myview')
is called from a script (e.g. a cronjob), not through the web server process, only /myview
is returned without the desired prefix URL. My example script looks like this:
import sys
import os
import django
sys.path.append('/var/www/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
django.setup()
from django.core.urlresolvers import reverse
print reverse('myview') # prints '/myview'
Is there a way to include the prefix URL when running outside of the web server context, so that the same reverse('myview')
code can be run from both contexts and returns the same value?