繁体   English   中英

Python烧瓶获得404未找到错误

[英]Python Flask getting 404 Not Found Error

我正在使用Flask设计这个简单的网站。 但我的hello方法遇到404错误。 每当我点击“评价艺术家”按钮时,它都会给我错误,但home.html,hello.html和artist.html的模板都是正确的。 我不知道我的代码的哪一部分是错的。 有帮助吗?

@app.route("/",methods=['GET','POST'])
def login():
    if request.method=="GET":
        return render_template("home.html")
    if request.method=="POST":
        if (request.form["button"]=="login"):
            return render_template("hello.html",name=request.form["name"])

@app.route("/hello",methods=['GET','POST'])
def hello():
    if request.method=="GET":
        if(request.form["button"]=="rate artists"):
            return render_template("artist.html")

我遇到了同样的问题。

我正在骨干和Flask之间进行一些实验性的CORS测试,作为不同网址的端点

您是在Config对象中使用SERVER_NAME还是在使用app.run时?

我把SERVER_NAME但没有指定端口,

class Config(object):
    DEBUG = True
    TESTING = True
    STATIC_FOLDER = STATIC_FOLDER
    STATIC_URL = STATIC_URL
    NAVIGATION_JS = '/static/js/navigation.js'
    SESSION_COOKIE_SECURE = True
    REDIS_HOST_SESSION = 'localhost'
    REDIS_PORT_SESSION = 6379
    REDIS_DB_SESSION = 2
    REDIS_HOST = 'localhost'
    REDIS_PORT = 6379
    REDIS_DB = 3
    SERVER_NAME = 'api.jvazquez.com.ar'

服务器名称没有端口

我所定义的任何路线也都得到404( 如果您有兴趣,我正在使用蓝图

当我使用curl向我的烧瓶应用程序发送请求时,我得到404,这是我得到的所有蓝图的输出404

jvazquez@aldebaran:~$ curl -i http://api.jvazquez.com.ar:5000/alive/
HTTP/1.0 404 NOT FOUND
Content-Type: text/html
Content-Length: 233   
Set-Cookie: session=94c2c120-34c0-4a00-b094-7b5623d438ff; Domain=.api.jvazquez.com.ar; HttpOnly; Path=/
Server: Werkzeug/0.9.4 Python/2.7.3
Date: Wed, 25 Dec 2013 11:21:16 GMT

因此,请检查是否已定义配置变量SERVER_NAME并具有端口

无论出于什么原因,当我将SERVER_NAME设置为127.0.0.1而不是localhost时,我都会遇到此问题。 我不知道为什么这对我的设置很重要,但在将其更改为localhost一切都开始了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM