I created class based view to access uid and token . Here I create one web page which have one button of activate user. I am sending one uid and token to user email . now I want to post that uid and token when user click on button. I create this code in view for post uid and token. But getting error on posting (WSGIRequest' object has no attribute 'post)
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() + '/'
post_url = web_url + ACTIVATION_BASE_ROUTE
print('post_url : ' + post_url)
response = request.post(post_url, data = payload)
return HttpResponse(response.text)
activate.html
<form action="" method="post">
{% csrf_token %}
<td ><button type="submit">Click Here For Activate Account</button></td>
</form>
How can I post it on same page ?
it should be requests not request
Give this a try
import requests
class ActivationView(View):
def post (self, request, uid, token):
...
response = requests.post(post_url, data = payload)
return HttpResponse(response.text)