how to redirect to a url with query string django

后端 未结 4 1133
星月不相逢
星月不相逢 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:46

    To redirect to another page while carrying along the the current query strings:

    views.py:

    from django.urls import reverse
    from django.shortcuts import redirect
    
    def my_view(request):
        #get the current query string
        q = request.META['QUERY_STRING']
        return redirect(reverse('search_view') + '?' + q)
    

提交回复
热议问题