Good day. The essence of the problem: I redirect to urlpatterns with the redirect_to function to a specific address, you need to pass a Russian text line along the way (although you can just have the boolean name = 1 for example). Now implemented as a getter parameter in url, here:

(r'^foo/$', redirect_to, {'url': '/bar?check=1'}), 

But something seems to me that it is possible and somehow more elegant, without using het parameters, simply by specifying the variable = value. Any thoughts? Or is my method the only one?

Oh yeah, it would also be nice to get into the request request to use its data in compiling the url (specifically, we need information about the current user, i.e. request.user). Is there any way to define a user in urlpatterns? Thank.

    2 answers 2

    Yuzay urlencode.

     import urllib # Это твои GET-параметры, которые ты как-то сюда передал param1 = 'value1' param2 = 'value2' # Твой какой-то код, паттерны params = urllib.urlencode({'param1': param1, 'param2': param2}) (r'^foo/$', redirect_to, {'url': '/bar?%s' % params}), 
    • In principle, a good way to Russian lines, but this is not entirely critical. Ideally, so that the parameters do not flash at all, but are transmitted in the background. But thanks for the answer! I'll take a note. - metazet

    Do not suffer with a redirect, the obvious is better than the implicit. Transfer control to views.py

     (r'^foo/$', 'my_view') 

    And there already are both request, request.GET.get ('check'), and request.user.

    • No, you just need a redirect, because there is a return to the page that hangs on a strictly defined address. And the response of one page to two different addresses for me is not allowed ... - metazet
    • And what prevents from the view to make HttpResponseRedirect? - MyNameIss
    • A view from the Jung library, and it is not good to rule. - metazet 4:34 pm