2012-11-24 53 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後,所有事情都再次開始。