how to redirect to a url with query string django

后端 未结 4 1020
星月不相逢
星月不相逢 2020-12-31 06:16

AoA, How can I goto a specific URL with parameters like if I have view

def search(request):

and in urls.py

^search/$ 
         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-31 06:50

    the answer is pretty simple. Using reverse and passing name of url can redirect to url with query string

    urls.py

    url(r'^search/$', views.search, name='search_view')
    

    views.py

    from django.shortcuts import redirect, reverse
    
    # in method
    return redirect(reverse('search_view') + '?item=4')
    

提交回复
热议问题