I am trying to build a Python Flask application, but I cannot access it. Flask recognizes the request, but for some reason doesn’t execute the function. Here is my code:
JavaScript
x
9
1
from flask import Flask, render_template
2
3
app = Flask(__name__)
4
5
app.route("/")
6
def main_page():
7
print("main_page() was called")
8
return render_template("main_page.html")
9
I am currently running it by typing flask run
the Windows CMD. The GET request is detected, but main_page
is not called and 404 is returned.
127.0.0.1 - - [01/Apr/2022 18:07:55] "GET / HTTP/1.1" 404 -
If anyone can help I would appreciate it.
Advertisement
Answer
You have missed ‘@’ in app.route, it should be
JavaScript
1
2
1
@app.route('/')
2
Few points, you can try debug mode, not sure with flask run. By adding main method
JavaScript
1
3
1
if __name__ == "__main__":
2
app.run(debug=True)
3
I tried below command python file.py runserver -d