簡體   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