5

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.

3

2 Answers 2

6

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"," ")
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']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.