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")
I'm having the same problem.
I'm doing some experimental CORS tests between backbone and Flask as an endpoint in a different url
Are you using SERVER_NAME in your Config object or when you use the app.run ?
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'
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)
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
So, check if you have defined the config variable SERVER_NAME and it has the port
For whatever reason I encountered this when I set the SERVER_NAME to 127.0.0.1
instead of localhost
. I don't know why that was important with my setup, but after changing it to localhost
everything started working again.