it shows the function related to root url i.e. ('/') but if i write @app.route('/home') it gives me that error
Based on your clarifying comments, it appears your browser is accessing a previous version of your app server.
I have run into this problem myself when using the PyCharm IDE. On Windows, the way to shut down these old versions of the server is to press either Ctrl+Alt+Delete
or Ctrl+Shift+Esc
(Windows 10) to view your list of running processes. Then scroll down until you see processes named Python
and shut them all down.
I don't know if it's due to some other python application running or something, but when I was a beginner in Flask I got a similar error to you.
I wrote app.route('/')
instead of @app.route('/')
(I missed the @
symbol).
See whether it's the case for your code.
You should have written @app.route('/home/'). That fixed the problem for me!
My solution to this problem: is to switch this instruction
if __name__ == "__main__":
app.run(debug=True ,port=8080,use_reloader=False)
as in the example bellow
from flask import Flask, render_template, request
app = Flask(__name__,template_folder="template")
@app.route("/")
def hello():
return render_template('index.html')
if __name__ == "__main__":
app.run(debug=True ,port=8080,use_reloader=False)
@app.route('/register', methods=['POST'])
def register():
query = request.form.get('query1')
selected = request.form.get('query')
if (not query or not selected):
return 'failure'
processed_text = query.upper()
return render_template('sucess.html')
to the end of your script (same example):
from flask import Flask, render_template, request
app = Flask(__name__,template_folder="template")
@app.route("/")
def hello():
return render_template('index.html')
@app.route('/register', methods=['POST'])
def register():
query = request.form.get('query1')
selected = request.form.get('query')
if (not query or not selected):
return 'failure'
processed_text = query.upper()
return render_template('sucess.html')
if __name__ == "__main__":
app.run(debug=True ,port=8080,use_reloader=False)
UPDATE---------------------------------
You should also take care of the local file. Please put them in the statistic field then use url_for from the Flask framework to create a correct URL
<div style = "text-align: center;">
<a href="{{ url_for('static',filename=path)}}">
<button class="slide_from_bottom button">check here </button>
</a>
</div>
I initially tried with @app.route("/hello") where the function I defined inside was def hello(): return "some statement" this gave me the error stated above, I removed "/hello" and tried with "/" this resolved the issue for me. p.s(I did this in pycharm and os is windows 10)
In your browser change the url from:
http://127.0.0.1:5000
To:
http://127.0.0.1:5000/about
whatever you are adding @app.route("/about")
here
I had this issue after deploying a legacy Python Flask application to Azure App Service for my team.
I was getting the error:
Not Found. The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
Here's how I fixed it:
The issue was that the URL I was entering wasn't the right one. Apparently, the developers did not set a root route, so instead of this:
https://my-website.com
You will have to specify the path to the resource you want, so we will have:
https://my-website.com/my-desired-path
That's all
You might have missed @
before the app.route('/')
<div style = "text-align: center;">
<a href="{{ url_for('static',filename=path)}}">
<button class="slide_from_bottom button">check here </button>
</a>
</div>
Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
I also encountered the same error just recently. This is what I did and it worked:
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def home_page():
return render_template("index.html")
@app.route("/about")
def about():
return render_template("about.html")
if __name__ == "__main__":
app.run(debug=True)
The "about" HTML page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>About Us</title>
</head>
<body>
<h1>About Us</h1>
<p>Learn about our company.</p>
<**a href="{{ url_for('about') }}"**>About</a>
</body>
</html>
As you can see, in the updated "about.html" file, I have added an anchor tag with the href attribute set to {{ url_for('about') }}, which uses the Flask url_for function to generate the URL for the about page based on the route specified in your Flask app. It ensures that the URL in your HTML code matches the route specified in your Flask app. Here is the Documentation.
It's because when you switch it to '/home', '/' does not exist anymore and thus gives a 404 error. (flask default is '/')
This error can be occur due to period @app.route("/.", methods =['GET'])
Correct one is @app.route("/", methods =['GET'])
Thanks
I encountered the same problem but it was immediately solved once I restarted my laptop.
<div style = "text-align: center;">
<a href="{{ url_for('static',filename=path)}}">
<button class="slide_from_bottom button">check here </button>
</a>
</div>
<div style = "text-align: center;">
<a href="{{ url_for('static',filename=path)}}">
<button class="slide_from_bottom button">check here </button>
</a>
</div>
<div style = "text-align: center;">
<a href="{{ url_for('static',filename=path)}}">
<button class="slide_from_bottom button">check here </button>
</a>
</div>
© 2022 - 2024 — McMap. All rights reserved.
/home
route? And can you paste all of the code in your app.py file? – Scaffold