I have a website that uses Flask. It used to work well, but since recently, every request returns a 404, and it seems it can't find the right endpoints. However:
url_for
works and app.view_functions
contains all the routes as well./
and anything under /static/
.Here's part of the code, it's a bit much to show all of it and it's not all relevant:
#snip from flask import Flask, render_template, abort, request, redirect, url_for, session from flask.ext.babelex import Babel from flask.ext import babelex #snip app = Flask(__name__) app.secret_key = #snip #snip #just one of the routes @app.route('/') def about(): return render_template('about.html') #snip @app.errorhandler(404) def page_not_found(e): #snip return render_template('404.html'), 404 #snip if __name__ == '__main__': app.run(debug=True) else: app.config.update( SERVER_NAME='snip.snip.com:80', APPLICATION_ROOT='/', )
404 error means the service is not returning any response. If you can observe between this tag it will return page not found text which means it returns a web page. What you can do is find the "Page not found" text inside the returned webpage. use string.
status_code attribute: if r. status_code == 404: # A 404 was issued. If you want requests to raise an exception for error codes (4xx or 5xx), call r.
Flask uses a concept of blueprints for making application components and supporting common patterns within an application or across applications. Blueprints can greatly simplify how large applications work and provide a central means for Flask extensions to register operations on applications.
I had the same issue. I had it because I changed the parameters SERVER_NAME
of the config to a name which is not the name of the server.
You can solve this bug by removing SERVER_NAME
from the config if you have it.
I know this is old, but I just ran into this same problem. Yours could be any number of issues but mine was that I had commented out the from app import views
line in my __init__.py
file. It gave me the same symptom: every endpoint that required @app.route
and a view was responding with 404's. Static routes (.js and .css) were fine (that was my clue).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With