0

Being a newbie, I am unfamiliar with the nomenclature with which to describe parts of code I am having trouble with. This makes it very difficult to look up information on the internet! The snippet of code below is from a template called 'buy.html'.

I am trying to find out how to access the fields/forms called 'quote' and 'shares' in python. How do 'quote' and 'shares' relate to 'buy.html'? I don't really know how to ask the question. For instance, can I access a specific field within my python code by typing 'buy.quote' or 'buy.shares'?

{% block title %}
    Buy Stocks
{% endblock %}

{% block main %}
    <form action="{{ url_for('buy') }}" method="post">
        <fieldset>
            <div class="form-group">
                <input autocomplete="off" autofocus class="form-control" name="quote" placeholder="Stock Symbol" type="text"/>
            </div>
            <div class="form-group">
                <input autocomplete="off" autofocus class="form-control" name="shares" placeholder="Number of Shares" type="int"/>
            </div>

1 Answer 1

0

You'd have to specify those in your render_template call, as a list of name-value pairs (I'm using static strings in this example, but those could be variables as well)

python:

return render_template("greetings.html", first_name = "John", last_name = "Doe")

greetings.html:

<h1>Hello, {{first_name}} {{last_name}}!</h1>

renders to

<h1>Hello, John Doe!</h1>
1
  • Thanks, I will try this. Commented Mar 24, 2017 at 17:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .