python - Django Hidden Redirection -


I want to create a mechanism for in-app redirecting which will not redirect, but simply load another view function Please. So we say that I am going to localhost: 8000 / a , the digenano looks at the last line of the scene and says

  Returns HTTPRPSPoint Redirect ('/ B ')   

will now go to my browser localhost: 8000 / b>, see Django and return it to me.

Now I want to do only on the server side, so when I go to localhost: 8000 / a and redirecting Django to / b , Then it gives the view for / b returns to all intermediate etc. (such as redirection will work) and without any redirection without any redirection (as for the user Has been observed).

I have called this type of redirection HttpResponseSmartRedirect and just like this: (which runs in the form of all middlemen), want to create midware for that time, that Is: Example of process_response check if response class HttpResponseSmartRedirect on

. Now I have a problem - when I go to that position - how does the reaction actually arise with the url? I can easily get the visual function by using resolution () to urlsolvers , but I do not know that it should go through all the middle classes and have the same reaction How to make it compulsory I will get with accidental redirection. The closest way to do this is to call urllib2.get (url) , but seeing that line, I have to destroy my computer.

How can I make any ideas how well it is ugly without urllib s?

You need to add the original request again at the bottom of the DNS request processing code.

Requests are started from BaseHandler.get_response to django.core.handlers. Base .

Then the solution will be something like this (untested!): Django.core.handlers.base import from BaseHandler class SmartRedirectMiddleware (object): def process_response (auto, request, Response): If iStance (Response, HTTPSMRRRERCRPS): Handler = Besandler () request.url = response.redirect_url resp = Handler .get_response (request) Return resp

For real use, you Want some protection against loops and unlimited recycling.

Or you can solve the problem differently - facilitate the browser to be restored based on the redirect. If it should be invisible, then it is easy to get acquainted with some client-side javascript.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -