Question:
I’d like to learn flask to create backends for my websites, but I’m not sure where to start.
Personally, I studied Flask solely on its documentation.
I recommend you to start with this flask documentation page:
https://flask-docs.readthedocs.io/en/latest/quickstart/
It briefly describes the main functions of flask (despite version 2.3.x, the information in the documentation is still relevant).
After studying the brief documentation, I recommend that you start creating some simple project, for example, a blog site with registration, creating articles and comments (if you have any problems, refer to the flask 3.0.x documentation or Google).
I told you how I studied flask.
There are a few resources on Ask
It would be easier to do this with JavaScript than with Flask, but I can make a similar site for you using Flask.
I’m just curios how to update text on a website based on a data that can be updated by the user.
To implement such a site using Flask, you would have to put the button in the form tag. When the Flask server would receive a POST request from this form, it would change the counter variable and return the page with the changed number to the user.
If you put together what is taught in the links I sent you:
main.py
from flask import Flask, redirect, render_template, request
app = Flask(__name__)
# Define the number variable. This won't save if you close and reopen the tab.
number = 0
@app.route('/', methods=['GET', 'POST'])
def index():
global number
# Check if we want to see the number or update the number
if request.method == 'GET':
# Tell our HTML the number with Jinja
return render_template('index.html', number=number)
number += 1
# We have to return something.
# Let's take the user back so they can see the number.
return redirect('/')
if __name__ == '__main__':
app.run('0.0.0.0', 81)
templates/index.html
<!DOCTYPE html>
<html lang="en"
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>replit</title>
</head>
<body>
<p>The number is {{ number }}</p> <!-- Use Jinja to display the number -->
<form method="post"> <!-- Use a form to tell our server when to update the number -->
<button type="submit">PRESS TO INCREASE NUMBER</button>
</form>
</body>
</html>
But if you want to do something as simple as this just use JavaScript.
@QwertyQwerty88 Thank you so much! I’ll make sure to read over the provided articles. I’m working on a big project related to Geocaching, and hopefully flask will be able to help with the API side of it.
Flask is very easy to use and learn. I am sure you will study it without any problems.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.