1
votes

I'm using Bottle for a Python project and I've set the project to run on the localhost:8080 (Windows 10 laptop). I’ve coded the project on VS Code, however, when I start the debugger on VS Code’s integrated terminal,I am presented with Error 500 on my browser (Google Chrome).

The project worked fine on a TA's machine, however on my laptop, bottle isn't routing to the index page, even when I explicitly had it import it from the static_file and adding the root file to the ‘run’ function. I tried running the example from Bottlepy.org, and even that isn’t working.

The only thing that has worked was:

from bottle import run, route

@route('/')
def hello():
   return "If you're seeing this message, then bottle is working"
run(host='localhost', port=8080)

Again, I’ve ran:

from bottle import run, route, template

@route('/')
def hello():
   return template("index.html")
run(host='localhost', port=8080)

and

from bottle import run, route, static_file

@route('/static/')
def hello():
  return static_file('index.html', root='static')
run(host='localhost', port=8080)

Including the example from bottlepy.org, to which resulted in:

Error 500 Template 'index.html' not found.

Or

Error 500 ‘Template ‘/’ not found

I don’t believe it’s a PATH issue with Python, but it could be a JSON file issue with VS code. All the Python packages on my machine are updated and I’m out of ideas at the moment. Your suggestions/recommendations would be appreciated. Thank you.

1
It is likely a path issue. Can you print the cwd from within hello?ron rothman
The cwd within 'hello'? Could you clarify your question, please? I'm relatively new to Python.DeltaYankee

1 Answers

0
votes

Probably the issue is because the integrated shell executes the code in some other directory where the file 'index.html' is.

To help solve the issue, replace the file name with an absolute path, e.g.

@route('/static/')
def hello():
  return static_file(os.path.join(os.path.dirname(__file__), 'index.html'), root='static')