1

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}}?

1 Answer 1

3

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"].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.