Python Flask出现404 Not Found错误 [英] Python Flask getting 404 Not Found Error

查看:460
本文介绍了Python Flask出现404 Not Found错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am designing this simple website using Flask. But I am getting a 404 error for my hello method. 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. 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")

推荐答案

我遇到了同样的问题.

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

I'm doing some experimental CORS tests between backbone and Flask as an endpoint in a different url

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

Are you using SERVER_NAME in your Config object or when you use the app.run ?

我放置了SERVER_NAME,但未指定端口

I put the SERVER_NAME but did not specify the port,

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(如果您有兴趣,我正在使用蓝图)

I also was getting 404 for any of the routes I had defined (if you are interested, I'm using blueprints)

当我使用curl向我的烧瓶应用程序发送请求时,我得到了404,这是输出 我定义的所有蓝图都得到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

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并具有端口

So, check if you have defined the config variable SERVER_NAME and it has the port

这篇关于Python Flask出现404 Not Found错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆