add request.GET variable using django.shortcuts.redirect

前端 未结 4 1992
北荒
北荒 2020-12-04 19:14

Is possible to add GET variables in a redirect ? (Without having to modifiy my urls.py)

If I do redirect(\'url-name\', x)

I get HttpRespo

4条回答
  •  悲哀的现实
    2020-12-04 19:36

    I think it's worth noting that Django's RedirectView class has a built-in class attribute query_string which can be overridden or passed to as_view. If set to True, query_string will preserve the query string in the redirect. For example, you could put the following in urls.py:

    path('example-redirect/',
         RedirectView.as_view(url='https://example.com', query_string=True),
         name='example_redirect')
    

提交回复
热议问题