简体   繁体   English

Python烧瓶获得404未找到错误

[英]Python Flask getting 404 Not Found Error

I am designing this simple website using Flask. 我正在使用Flask设计这个简单的网站。 But I am getting a 404 error for my hello method. 但我的hello方法遇到404错误。 Whenever I click on the button "rate artists," it's giving me the error, but templates for home.html, hello.html, and artist.html are all correct. 每当我点击“评价艺术家”按钮时,它都会给我错误,但home.html,hello.html和artist.html的模板都是正确的。 I do not know what part of my code is wrong. 我不知道我的代码的哪一部分是错的。 Any help? 有帮助吗?

@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")

I'm having the same problem. 我遇到了同样的问题。

I'm doing some experimental CORS tests between backbone and Flask as an endpoint in a different url 我正在骨干和Flask之间进行一些实验性的CORS测试,作为不同网址的端点

Are you using SERVER_NAME in your Config object or when you use the app.run ? 您是在Config对象中使用SERVER_NAME还是在使用app.run时?

I put the SERVER_NAME but did not specify the port, 我把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'

Server name doesn't has the port 服务器名称没有端口

I also was getting 404 for any of the routes I had defined ( if you are interested, I'm using blueprints ) 我所定义的任何路线也都得到404( 如果您有兴趣,我正在使用蓝图

When I send a request to my flask app using curl, I was getting 404, here is the output I was getting 404 for all of the blueprints that I had defined 当我使用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

So, check if you have defined the config variable SERVER_NAME and it has the port 因此,请检查是否已定义配置变量SERVER_NAME并具有端口

For whatever reason I encountered this when I set the SERVER_NAME to 127.0.0.1 instead of localhost . 无论出于什么原因,当我将SERVER_NAME设置为127.0.0.1而不是localhost时,我都会遇到此问题。 I don't know why that was important with my setup, but after changing it to localhost everything started working again. 我不知道为什么这对我的设置很重要,但在将其更改为localhost一切都开始了。

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

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