Answer the question
In order to leave comments, you need to log in
How to display a Python (flask) variable in an HTML file?
I need to transfer the value of the hook variable from the python code to the html code. I don't understand how to use the syntax in it. An example of an attempt:
app = Flask(__name__)
@app.route('/')
def hello_world():
hook = 'aaaaaaa!'
return render_template('index.html')
<p class="lead"> {% if message %}
<p>{{ form.hook }}</p>
{% endif %}</p>
{% if message %}
<p>{{ hook }}</p>
{% endif %}
Answer the question
In order to leave comments, you need to log in
I don't understand how to use the syntax in it.
from flask import render_template
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
name = 'Бендер Сгибальщик Родригес'
return render_template('index.html',name=name)
app.run(host='0.0.0.0', port=5000,debug=True)
<html>
<head>
<title>Футурама</title>
</head>
<body>
<h2>Привет, {{name}}!</h2>
</body>
</html>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question