user3837956
user3837956

Reputation: 67

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()

Upvotes: 5

Views: 5666

Answers (2)

Jonathan E. Landrum
Jonathan E. Landrum

Reputation: 3162

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.

Upvotes: 2

ron rothman
ron rothman

Reputation: 18127

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

Upvotes: 2

Related Questions