#17376 closed Bug (worksforme)
reverse() function does not work in the middleware
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Core (URLs) | Version: | 1.3 |
| Severity: | Normal | Keywords: | reverse, middleware |
| Cc: | piotr@… | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
urls.py:
urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), #(r'^comments/', include('comments.urls')), ..... url(r'^index.html$', 'root.views.ShowRoot'), url(r'^$', 'root.views.ShowRoot', name='index'), #----------------------------------------- )
Middleware:
from django.core.urlresolvers import reverse class AddSomeJS(object): def process_request(self, Request): print('=>{}'.format(reverse('index'))) def process_response(self, Request, Response): print('=>{}'.format(reverse('index'))) return Response
In process_request reverse works properly. But in the process_response we get error:
ImproperlyConfigured at /admin/articles/article4dealers/4/
The included urlconf urls doesn't have any patterns in it
Request Method: GET
Request URL: http://localhost:8000/admin/articles/article4dealers/4/
Django Version: 1.3.1
Exception Type: ImproperlyConfigured
Exception Value:
The included urlconf urls doesn't have any patterns in it
Exception Location: C:\WEB\VE\kler\lib\site-packages\django\core\urlresolvers.py in _get_url_patterns, line 283
Python Executable: C:\WEB\VE\kler\Scripts\python.exe
Python Version: 2.7.1
...........................
Traceback:
File "C:\WEB\VE\kler\lib\site-packages\django\core\handlers\base.py" in get_response
178. response = middleware_method(request, response)
File "C:\WEB\kler\asv_media\middleware.py" in process_response
62. print('=>{}'.format(reverse('index')))
File "C:\WEB\VE\kler\lib\site-packages\django\core\urlresolvers.py" in reverse
391. *args, **kwargs)))
File "C:\WEB\VE\kler\lib\site-packages\django\core\urlresolvers.py" in reverse
312. possibilities = self.reverse_dict.getlist(lookup_view)
File "C:\WEB\VE\kler\lib\site-packages\django\core\urlresolvers.py" in _get_reverse_dict
229. self._populate()
File "C:\WEB\VE\kler\lib\site-packages\django\core\urlresolvers.py" in _populate
197. for pattern in reversed(self.url_patterns):
File "C:\WEB\VE\kler\lib\site-packages\django\core\urlresolvers.py" in _get_url_patterns
283. raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it" % self.urlconf_name)
Exception Type: ImproperlyConfigured at /admin/articles/article4dealers/4/
Exception Value: The included urlconf urls doesn't have any patterns in it
Change History (7)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 14 years ago
| Component: | Uncategorized → Core (URLs) |
|---|
comment:4 by , 14 years ago
| Cc: | added |
|---|---|
| Resolution: | → worksforme |
| Status: | new → closed |
Cannot reproduce
comment:6 by , 14 years ago
With Django 1.4a I am unable to reproduce your error. To be exact here are some lines from ./manage.py runserver output:
=>/ in =>/ out [04/Feb/2012 12:58:43] "GET /admin/auth/group/ HTTP/1.1" 200 3253 =>/ in =>/ out
I used almost the same as yours code, and my urls.py is:
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'asdf.views.index', name="index"),
)
Note:
See TracTickets
for help on using tickets.
The
finallyclause that doesurlresolvers.set_urlconf(None)to "Reset URLconf for this thread on the way out for complete isolation of request.urlconf" happens before response middleware is applied. "on the way out" is a bit later in the code (at least now) than where thatfinallyclause is placed. Seems that reset should be done after the response middleware has been applied.