[Python] Why is Flask giving 404 error for all routes?

Discussão em 'Python' iniciado por Stack, Agosto 29, 2025.

  1. Stack

    Stack Membro Participativo

    Flask is returning a 404 error for all routes, even the '/' route.

    I do have a lot of code but I don't know how to reduce it for this question.

    Here is a few of the files:

    main.py

    from flask import Flask, render_template

    app = Flask(__name__, instance_path='/Users/aditgar/PycharmProjects/100daysofcode')
    @app.route('/')
    def get_all_posts():
    return render_template('test.html')



    test.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    </head>
    <body>
    <h1>WORKSSHDJJDS</h1>
    </body>
    </html>


    This is just a MRE of the real version, which uses SQLAlchemy, sqlite, e.t.c.

    This was working perfectly until is stopped working all of a sudden, I am confused what the error is.

    Editor: VS Code

    This is from a Python course online called "100 Days of Code".

    Here is what I got from my flask list:

    Endpoint Methods Rule
    ---------------- --------- ---------------------------------
    about GET /about
    add_new_post GET, POST /new-post
    bootstrap.static GET /bootstrap/static/<path:filename>
    ckeditor.static GET /ckeditor/static/<path:filename>
    contact GET /contact
    delete_post GET /delete/<int:post_id>
    edit_post GET, POST /edit-post/<int:post_id>
    get_all_posts GET /
    login GET, POST /login
    logout GET /logout
    register GET, POST /register
    show_post GET /post/<int:post_id>
    static GET /static/<path:filename>

    Continue reading...

Compartilhe esta Página