I would like to write middleware (or some other method) for re-writing a request (AFAICT the contents of request.META['PATH_INFO']
) before the URL resolver. This is so I could pick it up as a component of the URL and treat it as another view argument.
Something like this:
def process_request(self, request):
request.META['PATH_INFO'] = "string to prefix/" + request.META['PATH_INFO']
But it looks like the URL resolver is getting in there first.
Is there any way to achieve this?
My middleware is installed as the first in the list.
EDIT: To clarify, I want to re-write this request:
http://something.com/my/view/
=> /something.com/my/view
http://somethingelse.com/my/view/
=> /somethingelse.com/my/view
etc in middleware before the url handler.
I am currently doing it with view decorators which modify the kwargs passed to the view funciton, but it doesn't quite feel right.
Why? My app is handling requests from multiple domains and I would like a way to deduce the domain in middleware and have it passed 开发者_如何学编程in as a view argument.
If you use wsgi, I think you can do the rewrite in the .wsgi script (that is before the request is given to django)
精彩评论