【发布时间】:2021-10-29 18:02:39
【问题描述】:
我创建了基于类的视图,其中在 get 方法中我调用了 html 页面 activate.html。并创建了 post 方法,我在其中发布了一些 json 数据。我想重定向同一页面并想发布数据。
当我运行 activate.html 页面时,我得到了它,但是当我点击激活用户的按钮时,它的打印与我在 get 方法中打印的相同
views.py
class ActivationView(View):
def get (self, request, uid, token):
print('get called in activate_user')
return render(request, 'activate.html')
def post(self, request, uid, token):
print('UID : ', uid)
print('Token : ', token)
payload = json.dumps({'uid': uid, 'token': token})
print("payload : " , payload)
protocol = 'https://' if request.is_secure() else 'http://'
web_url = protocol + request.get_host()
djoser_url = getattr(settings, 'DJOSER.ACTIVATION_URL')
post_url = web_url + djoser_url
print('post_url : ' + post_url)
response = request.post(post_url, data = payload)
return HttpResponse(response.text)
当我点击 html 中的 post 按钮时,我想以 json 格式打印 uid 和 token。
激活.html
<form action="" method="post">
{% csrf_token %}
<td input type="submit"><a href="" target="_blank" >Click Here For Activate Account</a></td>
</form>
【问题讨论】:
-
嗯,你有一个锚标签(
a),显然它会发出一个get请求......
标签: json django authentication django-urls django-class-based-views