【问题标题】:Django view that redirects to another domain重定向到另一个域的 Django 视图
【发布时间】:2018-10-19 23:18:06
【问题描述】:

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

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

这样做的方法是什么?

【问题讨论】:

标签: python django redirect payment


【解决方案1】:

这是生成的 url,我的意思是 'ssl.dotpay.pl/test_payment/?id=123456&amount={}&description={}'.format(123.00, 'Test')

请务必在您的网址前添加协议(或至少两个斜杠)。 这样,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)

您也可以使用django.shortcuts 中的redirect 而不是HttpResponseRedirect

【讨论】:

    【解决方案2】:

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

    from django.http import HttpResponseRedirect
    
    def theview(request):
        # your logic here
        return HttpResponseRedirect(<theURL>)
    

    【讨论】:

      猜你喜欢
      • 2018-10-26
      • 2020-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-10
      • 2013-09-02
      相关资源
      最近更新 更多