How should I go about learning Flask?

Question:
I’d like to learn flask to create backends for my websites, but I’m not sure where to start.

1 Like

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.

3 Likes

There are a few resources on Ask :slight_smile:

4 Likes

How do you make say, a website like this actually have functionality with Flask?

It would be easier to do this with JavaScript than with Flask, but I can make a similar site for you using Flask.

2 Likes

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.

1 Like

@KAlexK What would the code look like on the python and HTML side?

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.

4 Likes

@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.

4 Likes

Flask is very easy to use and learn. I am sure you will study it without any problems.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.