I am very new to using bottle but whenever I try to run my programs I always get the error Error 404: Not Found '/'. The app in my example is not fully functional yet but it should at least display something on the screen. Even with fully functional programs this happens. There are similar problems asked but none of the solutions in those have worked.
import bottle
from cork import Cork
from cork.backends import SQLiteBackend
sb = SQLiteBackend('sasdasd.db', initialize=True)
aaa = Cork(backend=sb)
app = bottle.Bottle()
def post_get(name, default=''):
return bottle.request.POST.get(name, default).strip()
@bottle.route('/login')
def login():
return '''
<form action="/login" method="post">
Username: <input name="username" type="text" />
Password: <input name="password" type="password" />
<input value="Login" type="submit" />
</form>
'''
@bottle.post('/login')
def login():
"""Authenticate users"""
username = post_get('username')
password = post_get('password')
aaa.login(username, password, success_redirect='/', fail_redirect='/login')
bottle.run()
As @Wooble points out in his comment, you need to register the route "/" if you expect your webapp to respond with anything other than a 404 for that path. Here's some code to illustrate:
@bottle.get('/')
def home():
return 'Hello!'
Now your webserver will respond with an HTTP 200 and a body of "Hello!" when you request /.
I realize this question is already answered for the OP, but I was having the same problem with a different cause. Make sure your run
command is after your route statements, not before, or you will get 404
errors for everything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With