V
V
Vitaly2019-03-28 02:17:00
Python
Vitaly, 2019-03-28 02:17:00

How to render html with flask?

All the best!
Sorry for the stupid question, but it doesn't work :( There is a
flask server, located in /user/server_dir/server.py and there is a folder that contains html and css files /usr/other_dir/some_dir/some.html
How to use flask server with /user/server_dir/server.py render /usr/other_dir/some_dir/some.html ?
PS python 2.7

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2019-03-28
@Scorpiored88

Patterns are searched relative to the project root.

D
DaniilDorovenko, 2019-04-15
@DaniilDorovenko

1. In the directory with the application, create a templates folder, put html there.
2. In the application (apparently server.py), import the template module: from flask import render_template
3. Next, create the following function for the root directory in the application:
@app.route('/')
def index():
return render_template('index .html')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question