Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

  • Locally, the site still works, only on my VPS it shows this strange behaviour.
  • url_for works and app.view_functions contains all the routes as well.
  • And yet, I keep getting 404s on the VPS, even for / 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='/',
    )
question from:https://stackoverflow.com/questions/24437248/unexplainable-flask-404-errors

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
315 views
Welcome To Ask or Share your Answers For Others

1 Answer

I had the same issue. I had it because I changed the parameters SERVER_NAMEof 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...