无法解释的Flask 404错误 [英] Unexplainable Flask 404 errors

查看:57
本文介绍了无法解释的Flask 404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Flask的网站.它曾经可以正常工作,但是自最近以来,每个请求都返回一个404,似乎找不到正确的端点.但是:

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:

  • 该站点在本地仍然可以使用,仅在我的VPS上可以显示这种奇怪的行为.
  • url_for 有效,并且 app.view_functions 也包含所有路由.
  • 但是,我仍然在VPS上获得404,即使是/以及/static/下的任何内容.
  • 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='/',
    )

推荐答案

我遇到了同样的问题.之所以拥有它,是因为我将配置的参数 SERVER_NAME 更改为不是服务器名称的名称.

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.

您可以通过从配置中删除 SERVER_NAME 来解决此错误.

You can solve this bug by removing SERVER_NAME from the config if you have it.

这篇关于无法解释的Flask 404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆