How do I redirect in Django with context?

前端 未结 5 1664
野的像风
野的像风 2020-11-30 03:49

I have a view that validates and saves a form. After the form is saved, I\'d like redirect back to a list_object view with a success message \"form for customer xyz was suc

5条回答
  •  無奈伤痛
    2020-11-30 04:19

    I found the following to work if more than just a message needs to be added to the redirect:

    from django.shortcuts import redirect
    import urllib
    
    def my_view(request):
    
        ...
    
        context = {'foo1': bar1, 'foo2': bar2, 'foo3': bar3}
        return redirect('/redirect_link/?' + urllib.parse.urlencode(context))
    

    See also how to pass context data with django redirect function?

提交回复
热议问题