The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again
Asked Answered
P

15

25

it shows the function related to root url i.e. ('/') but if i write @app.route('/home') it gives me that error

Panoply answered 6/7, 2017 at 12:48 Comment(2)
Did you reload your app after you added the /home route? And can you paste all of the code in your app.py file?Scaffold
I had reloaded it. I will try your suggestion. I think I have got the actual problem. the flask server is still running in spite of closing the editor and all code related stuff it shows me the output for '/' root url. I tried the change the contents but still it shows earlier returned data. that means it is running somewhere else. I have to find it where it is running...in the background!!!Panoply
S
23

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.

Scaffold answered 6/7, 2017 at 13:22 Comment(3)
---1 Delete running old instances of phyton exe ---2 in edit option provide script path =app.py and parametes =FLASK_APP=app.js and select pip interpreter as project defaulDb
This also works on Azure Web Service, when ever anyone gets this type of error go to home page of your azure portal and simply restart the Web Service by hovering mouse over the resource and clicking restart.Actable
Thank you. I've just backed out a load of changes thinking one of them was causing this even though I knew that it had worked previously. Restarted PyCharm and it worked. Will remember this one.Broad
M
10

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.

Merlenemerlin answered 16/10, 2020 at 22:7 Comment(0)
E
3

You should have written @app.route('/home/'). That fixed the problem for me!

Eastbound answered 4/5, 2021 at 4:23 Comment(1)
Definitely this answer for me, seems to also match the question exactlyGoldia
A
2

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>
Approach answered 30/11, 2021 at 15:44 Comment(0)
F
1

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)

Fibrillation answered 21/6, 2021 at 6:46 Comment(0)
M
1

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

Mccune answered 17/1 at 11:14 Comment(0)
A
0

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

Auriferous answered 26/10, 2021 at 21:32 Comment(0)
F
0

You might have missed @ before the app.route('/')

Foretopmast answered 9/1, 2022 at 13:23 Comment(0)
B
0

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

Benefactor answered 23/11, 2022 at 3:41 Comment(0)
J
0

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.

Josiahjosias answered 14/3, 2023 at 12:55 Comment(0)
A
0

It's because when you switch it to '/home', '/' does not exist anymore and thus gives a 404 error. (flask default is '/')

Anyplace answered 15/5, 2023 at 23:25 Comment(0)
L
0

This error can be occur due to period @app.route("/.", methods =['GET']) Correct one is @app.route("/", methods =['GET']) Thanks

Leonidaleonidas answered 24/7, 2023 at 10:7 Comment(0)
L
0

I encountered the same problem but it was immediately solved once I restarted my laptop.

Lalalalage answered 12/8, 2023 at 16:38 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Corrie
T
0

<div style = "text-align: center;">
  <a href="{{ url_for('static',filename=path)}}">
    <button class="slide_from_bottom button">check here </button>
  </a>
</div>
Trammel answered 8/7 at 2:0 Comment(1)
Your answer could be improved by adding more information on what the code does and how it helps the OP.Hoem
T
0

<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>
Trammel answered 8/7 at 3:37 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Corrie

© 2022 - 2024 — McMap. All rights reserved.