Changes between Initial Version and Version 2 of Ticket #9805
- Timestamp:
- Dec 11, 2008, 7:43:51 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #9805
- Property Summary reverse() does not add SCRIPT_NAME to the returned URL if called from modules that contain middleware → reverse() does not add SCRIPT_NAME to the returned URL if called from middleware modules
- Property Owner changed from to
-
TabularUnified Ticket #9805 – Description
initial v2 1 1 For example, take the following middleware.py file, with one example middleware thing that redirects you to the login page if you are not logged in: 2 2 3 {{{login_url=reverse('login') 3 {{{ 4 #!python 5 login_url=reverse('login') 4 6 5 7 class LoginMiddleware(): … … 7 9 if(request.user.is_anonymous() and request.path!=login_url): 8 10 #force login 9 return HttpResponseRedirect(login_url+'?next='+request.path)}}} 11 return HttpResponseRedirect(login_url+'?next='+request.path) 12 }}} 10 13 11 14 In this case, login_url will be correct except for the fact that it will be missing the SCRIPT_NAME. Putting the reverse() call inside the process_request function solves the problem, but it makes no sense at all to call that reverse function for every request when it can be called once at server startup. … … 14 17 15 18 {{{ 19 #!python 16 20 if self._request_middleware is None: 17 21 self.load_middleware()