How to redirect to another domain with python django and pass additional informations?
如何使用python django重定向到另一个域并传递其他信息?
For example i want to redirect to https://ssl.dotpay.pl/test_payment/ and give additional informations so url will look like this https://ssl.dotpay.pl/test_payment/?id=123456&amount=123.00&description=Test but I don't want to generate url in my view, just pass the data in json or something like that.
例如,我想重定向到https://ssl.dotpay。pl/test_payment/并提供额外的信息,因此url看起来就像这个https://ssl.dotpay.pl/test_payment/?id=123456&amount=123.00&description=Test,但是我不想在我的视图中生成url,我只想用json之类的方式传递数据。
What is the way to do this?
怎么做呢?
2 个解决方案
#1
1
this is generated url by what i meant 'ssl.dotpay.pl/test_payment/?id=123456&amount={}&description={}'.format(123.00, 'Test')
这是由我的意思是“ssl.dotpay.pl/test_payment/?id=123456&amount={}。format(123.00,‘Test’)生成的url。
Be sure to put a protocol before your url (or at least two slashes). This way, Django will see it as an absolute path. From your comment it seems you redirect to ssl.dotpay.pl
what will be seen as a local path rather than another domain.
一定要在你的url前放一个协议(或至少两个斜杠)。这样,Django将把它视为一条绝对的路径。从你的评论看来,你转向了ssl.dotpay。将被视为本地路径而不是另一个域的。
This is what I came across. (See question I put on * and answer)
这就是我遇到的。(参见我在*上的问题和答案)
So in your case, you can use the following:
因此,在你的案例中,你可以使用以下内容:
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)
You could also use redirect
from django.shortcuts
instead of HttpResponseRedirect
您还可以使用django的重定向。快捷键,而不是HttpResponseRedirect
#2
1
Assuming you are using a functional view, you could probably do something like this in your view:
假设你使用的是功能视图,你可能会在你的视图中这样做:
from django.http import HttpResponseRedirect
def theview(request):
# your logic here
return HttpResponseRedirect(<theURL>)
#1
1
this is generated url by what i meant 'ssl.dotpay.pl/test_payment/?id=123456&amount={}&description={}'.format(123.00, 'Test')
这是由我的意思是“ssl.dotpay.pl/test_payment/?id=123456&amount={}。format(123.00,‘Test’)生成的url。
Be sure to put a protocol before your url (or at least two slashes). This way, Django will see it as an absolute path. From your comment it seems you redirect to ssl.dotpay.pl
what will be seen as a local path rather than another domain.
一定要在你的url前放一个协议(或至少两个斜杠)。这样,Django将把它视为一条绝对的路径。从你的评论看来,你转向了ssl.dotpay。将被视为本地路径而不是另一个域的。
This is what I came across. (See question I put on * and answer)
这就是我遇到的。(参见我在*上的问题和答案)
So in your case, you can use the following:
因此,在你的案例中,你可以使用以下内容:
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)
You could also use redirect
from django.shortcuts
instead of HttpResponseRedirect
您还可以使用django的重定向。快捷键,而不是HttpResponseRedirect
#2
1
Assuming you are using a functional view, you could probably do something like this in your view:
假设你使用的是功能视图,你可能会在你的视图中这样做:
from django.http import HttpResponseRedirect
def theview(request):
# your logic here
return HttpResponseRedirect(<theURL>)