2012-11-24 49 views
2

我正在使用烧瓶设计这个简单的网站。但是我的hello方法出现了404错误。每当我点击按钮“率艺术家”,它给我的错误,但home.html,hello.html和artist.html模板都是正确的。我不知道我的代码的哪一部分是错的。任何帮助?Python烧瓶得到404未找到错误

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

正如你所知,你的'if'语句看起来像'if(...):',而他们工作,实际上并不是普遍接受的约定。例如:倒数第二行: 'if request.form ['button'] =='rate artists':' – jdotjdot

+2

此外,您还需要提供更多信息供人帮助。只是说,如果你没有提供关于按钮的信息,那么“rate artists”按钮不起作用就无济于事。 – jdotjdot

+0

“/ hello?button = rate + artists”是否也返回404错误? –

回答

5

我遇到同样的问题。

我你是否在你的配置对象使用SERVER_NAME做骨干和瓶之间的一些实验CORS测试作为终点在不同的URL

或当您使用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所有的蓝图是我已经定义

[email protected]:~$ 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它具有端口

2

无论出于何种原因,我遇到了这个当我设置SERVER_NAME到127.0.0.1,而不是localhost。我不知道为什么这对我的设置很重要,但将其更改为localhost后,所有事情都再次开始。