Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#17376 closed Bug (worksforme)

reverse() function does not work in the middleware

Reported by: stalker@… 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


urlpatterns = patterns('',
    url(r'^admin/', include(,
    #(r'^comments/', include('comments.urls')),
    url(r'^index.html$', 'root.views.ShowRoot'),
    url(r'^$', 'root.views.ShowRoot', name='index'),


from django.core.urlresolvers import reverse

class AddSomeJS(object):
  def process_request(self, Request):

  def process_response(self, Request, Response):
    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\ in _get_url_patterns, line 283
Python Executable: 	C:\WEB\VE\kler\Scripts\python.exe
Python Version: 	2.7.1


    File "C:\WEB\VE\kler\lib\site-packages\django\core\handlers\" in get_response
      178.                 response = middleware_method(request, response)
    File "C:\WEB\kler\asv_media\" in process_response
      62.         print('=>{}'.format(reverse('index')))
    File "C:\WEB\VE\kler\lib\site-packages\django\core\" in reverse
      391.             *args, **kwargs)))
    File "C:\WEB\VE\kler\lib\site-packages\django\core\" in reverse
      312.         possibilities = self.reverse_dict.getlist(lookup_view)
    File "C:\WEB\VE\kler\lib\site-packages\django\core\" in _get_reverse_dict
      229.             self._populate()
    File "C:\WEB\VE\kler\lib\site-packages\django\core\" in _populate
      197.         for pattern in reversed(self.url_patterns):
    File "C:\WEB\VE\kler\lib\site-packages\django\core\" 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 Changed 6 years ago by Karen Tracey

The finally clause that does urlresolvers.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 that finally clause is placed. Seems that reset should be done after the response middleware has been applied.

comment:2 Changed 6 years ago by Karen Tracey

Triage Stage: UnreviewedAccepted

comment:3 Changed 6 years ago by Aymeric Augustin

Component: UncategorizedCore (URLs)

comment:4 Changed 6 years ago by Piotr Banaszkiewicz

Cc: piotr@… added
Resolution: worksforme
Status: newclosed

Cannot reproduce

comment:5 Changed 6 years ago by stalker@…

I am sorry, but what You can't reproduce?

comment:6 Changed 6 years ago by Piotr Banaszkiewicz

With Django 1.4a I am unable to reproduce your error. To be exact here are some lines from ./ 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 is:

urlpatterns = patterns('',
    url(r'^admin/', include(,
    url(r'^$', 'asdf.views.index', name="index"),

comment:7 Changed 6 years ago by stalker@…

thanks! I will be wait new release...

Note: See TracTickets for help on using tickets.
Back to Top