4

I have a django template which has multiple <a> tags.

<a class="label label-success" href="get_status/?token={{book.token}}">Update</a>

On click of it, a method from views is called where I can access the token from the url as

tkn = request.GET.get('token')

But now I want not to send the token in the url.
I searched for this and get to know about forms but I did not clearly understand them. Can anyone please help here.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Aman Gupta
  • 1,764
  • 4
  • 30
  • 58

2 Answers2

5

For future ref: I created a form and added a hidden input field in it. on click of submit button it will send the token value.

<form action="get_Status/" method="post">
{% csrf_token %}
{{ form }}
<input type="hidden" name="book_token" value="{{book.token}}">
<input type="submit" class="submit_btn btn label-success" value="Update" />
</form>

Ans in the views.py

book_token=request.POST.get("book_token"," ")
Aman Gupta
  • 1,764
  • 4
  • 30
  • 58
1

You can use the basic HTML form concept here.

Please check the link:

How to submit a form with JavaScript by clicking a link? Use javascript/Jquery to submit the form.

Insert the token value in a hidden field and use form to submit it to views.

Then in the views,you can get the value as :request.POST['token']

Community
  • 1
  • 1