mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
middleware: Don't interfere in 404 URLs in setup
Don't raise a 404 exception when a page is not found. Instead, simply bypass the setup middleware so that other middleware have a chance to process further. Slight modification so that resolve method can be mocked during unittests.
This commit is contained in:
parent
f34cb78867
commit
cde615aee6
@ -20,7 +20,7 @@ Django middleware to show pre-setup message and setup progress.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.core.urlresolvers import resolve
|
from django.core import urlresolvers
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -40,7 +40,11 @@ class SetupMiddleware(object):
|
|||||||
"""Handle a request as Django middleware request handler."""
|
"""Handle a request as Django middleware request handler."""
|
||||||
# Perform a URL resolution. This is slightly inefficient as
|
# Perform a URL resolution. This is slightly inefficient as
|
||||||
# Django will do this resolution again.
|
# Django will do this resolution again.
|
||||||
resolver_match = resolve(request.path_info)
|
try:
|
||||||
|
resolver_match = urlresolvers.resolve(request.path_info)
|
||||||
|
except urlresolvers.Resolver404:
|
||||||
|
return
|
||||||
|
|
||||||
if not resolver_match.namespaces or not len(resolver_match.namespaces):
|
if not resolver_match.namespaces or not len(resolver_match.namespaces):
|
||||||
# Requested URL does not belong to any application
|
# Requested URL does not belong to any application
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user