how to redirect to a url with query string django

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

    A more generic option;

    from urllib.parse import urlencode
    from django.shortcuts import redirect as django_redirect
    
    
    def redirect(url, *args, params=None, **kwargs):
        query_params = ""
        if params:
            query_params += '?' + urlencode(params)
        return django_redirect(url+query_params, *args, **kwargs)
    
    

提交回复
热议问题