重定向到另一个域的 Django 视图
Django view that redirects to another domain
如何使用 python django 重定向到另一个域并传递附加信息?
例如,我想重定向到 https://ssl.dotpay.pl/test_payment/ 并提供其他信息,因此 url 将如下所示
https://ssl.dotpay.pl/test_payment/?id=123456&amount=123.00&description=Test
但我不想在我看来生成 url,只需将数据传递到 json 或类似的东西。
有什么方法可以做到这一点?
假设您使用的是功能视图,您可能会在视图中执行以下操作:
from django.http import HttpResponseRedirect
def theview(request):
# your logic here
return HttpResponseRedirect(<theURL>)
this is generated url by what i meant 'ssl.dotpay.pl/test_payment/?id=123456&amount={}&description={}'.format(123.00, 'Test')
一定要在 url(或至少两个斜杠)之前加上一个协议。
这样,Django 会将其视为绝对路径。
从您的评论来看,您似乎重定向到 ssl.dotpay.pl
将被视为本地路径而不是另一个域的路径。
这就是我遇到的。 (参见 I put on Whosebug and )
因此,对于您的情况,您可以使用以下内容:
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
如何使用 python django 重定向到另一个域并传递附加信息?
例如,我想重定向到 https://ssl.dotpay.pl/test_payment/ 并提供其他信息,因此 url 将如下所示 https://ssl.dotpay.pl/test_payment/?id=123456&amount=123.00&description=Test 但我不想在我看来生成 url,只需将数据传递到 json 或类似的东西。
有什么方法可以做到这一点?
假设您使用的是功能视图,您可能会在视图中执行以下操作:
from django.http import HttpResponseRedirect
def theview(request):
# your logic here
return HttpResponseRedirect(<theURL>)
this is generated url by what i meant 'ssl.dotpay.pl/test_payment/?id=123456&amount={}&description={}'.format(123.00, 'Test')
一定要在 url(或至少两个斜杠)之前加上一个协议。
这样,Django 会将其视为绝对路径。
从您的评论来看,您似乎重定向到 ssl.dotpay.pl
将被视为本地路径而不是另一个域的路径。
这就是我遇到的。 (参见
因此,对于您的情况,您可以使用以下内容:
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