mod_wsgi and url resolve (so confused, please help)

31 views
Skip to first unread message

The Bear

unread,
Sep 21, 2012, 12:09:50 PM9/21/12
to django...@googlegroups.com
Hi All

I am really stuck with resolving urls now i have moved my app to mod_wsgi environment.

Basically my problem is that when using a mod wsgi prefix valid urls will resolve in the usual general browsing way but not using teh resolve function directly

so
url = reverse('grant_and_save')

gives url as '/ethics/ethics/grantandsave/'

but when i do this https://mysite/ethics/ethics/grantandsave/ works just fine but

func, args, kwargs = resolve(url)

in my code gives the can't find page exception

{'path': 'ethics/ethics/grantandsave/', 'tried': [[<RegexURLResolver [<RegexURLPattern index ^$>, <RegexURLPattern logout ^logout/$>, <RegexURLPattern password_change ^password_change/$>, <RegexURLPattern password_change_done ^password_change/done/$>, ...............

I'm really confused as i don't really understand mod_wsgi.

I tried putting in a FORCE_SCRIPT_NAME setting of '/ethics' and of 'ethics' but that didn't help at all. I also tried hard coding various options into resolve() with no luck

here are my files

in httpd conf

WSGIDaemonProcess  ethics_project processes=4 threads=1 display-name=int_ethics_project inactivity-timeout=100 maximum-requests=1000

WSGIScriptAlias /ethics /srv/wsgi/intranetapps/virtualenvs/ETHICS_PROJECT/ethics_project/apache/django.wsgi
<Directory /srv/wsgi/intranetapps/virtualenvs/ETHICS_PROJECT/ethics_project/apache/>
    WSGIProcessGroup ethics_project
</Directory> 

and in djang.wsgi

import os, sys
from os.path import abspath, dirname, join
import site

proj_root = abspath(join(dirname(__file__), '..'))
major, minor = sys.version_info[:2] 
ALLDIRS = ['%s/lib/python%s.%s/site-packages' %(root, major, minor)]
# Remember original sys.path.
prev_sys_path = list(sys.path)
# Add each new site-packages directory.
for directory in ALLDIRS:
  site.addsitedir(directory)
# Reorder sys.path so new directories at the front.
new_sys_path = []
for item in list(sys.path):
    if item not in prev_sys_path:
        new_sys_path.append(item)
        sys.path.remove(item)
sys.path[:0] = new_sys_path
sys.path.append(root)
sys.path.append(proj_root)
sys.path.append('%s/web2ldap' %proj_root)
import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = django.core.handlers.wsgi.WSGIHandler()
import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = django.core.handlers.wsgi.WSGIHandler()

root = abspath(join(dirname(__file__), '../..'))

urls.py (project)

urlpatterns = patterns('',

    # Uncomment the next line to enable the admin:
    url(r'^ethics/admin/', include(admin.site.urls), name="admin_home"),
    (r'^ethics/', include('ethics.urls')),    
)
urlpatterns += staticfiles_urlpatterns()

and ethics/urls.py the pattern

url(r'^grantandsave/$', grant_and_save, name="grant_and_save"),

which resolves just fine if i go to the page






Reply all
Reply to author
Forward
0 new messages