getting get method when running post method

Shweta Shinde

I created class based view where In get method I am calling html page activate.html. and created post method where I posting some json data. I want to redirect same page and want to post data.

When I am running activate.html page I get it but when I click on button for activate user Its printing same which I print in get method

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)

I want to print uid and token in json format when I click on post button from html.

activate.html

<form action="" method="post">
      {% csrf_token %}
      <td input type="submit"><a href="" target="_blank" >Click Here For Activate Account</a></td>
 </form>
sarath ravi

change your form

<form action="" method="post">
  {% csrf_token %}
  <td ><button type="submit">Click Here For Activate Account</button></td>
</form>

this will works.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Getting NoSuchElementException when running this method

get response when i call the post method

Why does not the post method work when the Get method works in RestController?

is <a> tag post method or get method?

Flask running request.method 'POST' by default instead of 'GET'

Json file not getting updated when using post method in javascript?

AngularJS getting error on Post method

Getting errors in axios post method

Method Post and Get In CodeIgniter

Why does my method get stuck when running in Azure?

Getting a null object reference from Service when use method get

Getting error on Http GET method in Angular when converting object to array

Scrapy - FormRequest sends GET request when the method is POST

Why am I getting an error "The GET method is not supported for this route. Supported methods: POST." when I am actually making a post request?

Running a method when closing the program?

GET method with list of paramethers as body or POST method?

Http post method seen as http get method

Convert GET Method to POST Method in Flask

Body is not getting parsed in GET method

Why do I get an error when running a method from a jsp page, but not from a main method?

RestController with GET + POST on same method?

POST method is sent as GET to the servlet

FeignClient converts GET method to POST

GET and POST in same Flask method

SOAP POST method performs GET?

A form with POST method submitting a GET

Keyrock FIWARE method GET and POST

Why this ajax request is successful when request method is GET but fails in POST method

How to login with a scrapy spider when the login page is as GET method instead of a POST method?