Django查看重定向到另一个域

时间:2018-05-09 18:43:57

标签: python django redirect payment

如何使用python django重定向到另一个域并传递其他信息?

例如,我想重定向到https://ssl.dotpay.pl/test_payment/并提供其他信息,以便url看起来像这样 https://ssl.dotpay.pl/test_payment/?id=123456&amount=123.00&description=Test  但我不想在我的视图中生成url,只是传递json中的数据或类似的东西。

这样做的方法是什么?

2 个答案:

答案 0 :(得分:1)

假设您正在使用功能视图,您可以在视图中执行以下操作:

from django.http import HttpResponseRedirect

def theview(request):
    # your logic here
    return HttpResponseRedirect(<theURL>)

答案 1 :(得分:1)

  

这是由我的意思生成的网址&#39; ssl.dotpay.pl/test_payment/?id = 123456&amp; amount = {}&amp; description = {}&#39; .format(123.00,&#39 ;试验&#39)

请务必在您的网址之前添加协议(或至少两个斜杠)。 这样,Django将其视为绝对路径。 从您的评论中,您似乎会重定向到ssl.dotpay.pl将被视为本地路径而非另一个域。

这就是我遇到的情况。 (参见question我放置了stackoverflow和answer

因此,在您的情况下,您可以使用以下内容:

class MyView(View):
    def get(self, request, *args, **kwargs):
        url = 'https://ssl.dotpay.pl/test_payment/'
              '?id=123456&amount={}&description={}'.format(123.00, 'Test')
        return HttpResponseRedirect(url)

您还可以使用redirect中的django.shortcuts代替HttpResponseRedirect