Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bottle Python Error 404: Not found: '/'

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()
like image 698
user3837956 Avatar asked Oct 01 '22 06:10

user3837956


2 Answers

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 /.

like image 105
ron rothman Avatar answered Oct 06 '22 00:10

ron rothman


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.

like image 26
Jonathan E. Landrum Avatar answered Oct 06 '22 01:10

Jonathan E. Landrum