如何在django中传递绝对URL

时间:2013-05-16 22:07:50

标签: python django

如何将绝对URL传递给django函数并重定向到它?

def function(request):
    back_url = request.META['HTTP_REFERER']    # example.com/home/?status=80&page=1
    return redirect(back_url)

1 个答案:

答案 0 :(得分:3)

你可以这样做:

def func(request):
    url  = request.META['HTTP_REFERER']
    if request.META['QUERY_STRING']:
        url += '?%s' % request.META['QUERY_STRING']
    return redirect_to(request, url, **kwargs)