Reputation: 13
I am building an app using Flask to show nearby shops, and the user can like a shop so it can be added to their liked shops list.
My question is how can i get the value inside the <h4>
tag sent to Python knowing that the name attribute is a variable. The html code is below:
<form name='likeF' method='POST' action ='{{url_for("liked")}}'>
<h4 name="ShopName_{{loop.index}}">{{item.ShopName}}</h4>
<p>
Shop Description : {{item.ShopDesc}} <br>
<button type="submit" class="success button like">Like</button>
distance: {{item.ShopDistance}}
</p>
</form>
So please how am I supposed to get back the value of {{item.ShopName}}
?
Upvotes: 1
Views: 2874
Reputation: 59164
You can't send the text inside an <h4>
tag (or any tag that is not a form input) back to the server, at least not without using Javascript. The easiest method would be to duplicate it in a hidden input element inside the form, such as:
<input type="hidden" name="ShopName" value="{{ item.ShopName }}">
Then you can access it using request.form["ShopName"]
.
Upvotes: 3