Monday, June 27, 2016

Using django/mod_wsgi with apache httpd ErrorDocument seems to confuse reverse URL mapping

Hi, I'm trying to set up mod_wsgi and Django to handle authentication and I'm getting a weird problem. After much troubleshooting I've distilled it down to the configs below:

/etc/httpd/conf.d/10-django.conf
<VirtualHost *:80>
ServerName site.internal
DocumentRoot /home/user/git/standard-web-site-no-python-stuff/
alias /static/ /home/user/git/project/app/static/
<Directory "/home/user/git/project/app/static">
  Require all granted
</Directory>

<Directory "/home/user/git/project/app">
  <files "wsgi.py">
    Order Deny, Allow
    Allow from all
    Require all granted
  </Files>
</Directory>
WSGIDaemonProcess site.internal user=apache processes=2 threads=10 display-name=%{GROUP} python-path=/home/user/git/project
WSGIProcessGroup site.internal
WSGIScriptAlias /wsgi-app/ /home/user/git/project/app/wsgi.py
<Location "/">
  Order Deny, Allow
  Allow from all
  ErrorDocument 404 "/wsgi-app/"
</Location>
</VirtualHost>

My Django project is set up VERY simply with the following:
/home/user/git/project/app/wsgi.py
...imports...

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()


/home/user/git/project/app/views.py

def main(request):

  return render(request, "appname/template.tmpl")


def testme(request):

  return render(request, "appname/template2.tmpl")


/home/user/git/project/app/urls.py

urlpatterns = [

  url(r'^$', "app.views.main", name="app-main"),

  url(r'^testme/$', "app.views.testme", name="app-testme"),

]


/home/user/git/project/app/templates/app/template.tmpl

...HTML Stuff...

<a href="{% url "app-testme" %}>testme</a>

...More HTML stuff


--------------

The above app works 100% fine when I go to http://site.internal/wsgi-app/. If I hover over the "testme" anchor, I get http://site.internal/wsgi-app/testme/


BUT! If I go to http://site.internal/non-good-html.html and get redirected by the ErrorDocument 404 directive it shows my views.main() page.

When I hover over the "testme" anchor, I get http://site.internal/testme/ (***Notice the missing /wsgi-app/***)


It seems like the app namespace is not preserved when I'm rendering the main() page from an ErrorDocument directive.


I tried adding app_name="wsgi-app" to the urls.py but it doesn't change anything.


I must be missing something simple as this seems like an easy use-case to implement.


Pat

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aa74d449-18e7-43d5-9b5a-10d38239c1a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment