Hello,
What
you should realize is that developing a website with Flask is essentially writing regular Python code with a little bit of ‘website-specific code. Flask is very lightweight; it gives you the essentials, but that’s it — apart from plugins.
To start, you don’t need to know much more than the following:
You create a Flask instance
from flask import Flask
app = Flask(__name__) # don't worry about the __name__ bit for now
Each page is handled by a function, whose route is registered by a decorator
@app.route("/")
def index():
pass
The app. route bit simply registers the function below to a specific path. It’s an alternative to app.add_url_rule('/', 'index', index). It’s just telling the app to refer to the index function whenever a user requests ‘/’.
Each of these functions can render a website using the data that you got using ‘regular Python’
import datetime
from flask import render_template
def index():
current_dt = datetime.datetime.now()
render_template("index.html",
current_dt=current_dt)
You need a templates/index.html file which is written using Jinja2. This is regular HTML mixed with a specific syntax for logic and to use the data that ‘was sent to’ the template using the render_template function.
<html>
<head>
<title>My website
</head>
<body>
{{ current_dt.strftime("%H:%M" }} # using a custom filter would be better, but is out of the scope of this answer
</body>
</html>
You run your development server
app.run()
And that’s it. Your first Flask website shows the current time. Everything else just expands on this basis.
I hope this will help you