How to Use Bottle Static_file in Windows 10

Asked 1 years ago, Updated 1 years ago, 86 views

I started studying the framework at Spyder 3 (python 3.7).
I'm using a bottle, but 404 comes out.

Implemented with the following code:The filename is bottle2.py.
index.html is located in the folder views.
bottle.py is in the same folder.

Why does 404 come out?

Also, is index.html the extension of the text document html correct?

The contents of @route and the second argument of static_file appear to be incorrect.

Also, please tell me the meaning of this decorator.I couldn't find out when I looked it up.
Thank you for your cooperation.

 from bottle import route, run, static_file

@route('/')

defmain():
    return static_file('index.html', root='views')

run(host='localhost', port=9999)

python python3 windows spyder

2022-09-30 17:41

1 Answers

I don't use spyder and I use it from a command prompt, but I can use bottle2.py to display the following folder file configuration:

index.html is a text file, but it is written in HTML format (usually in UTF-8).I don't know what a text document is like, but it seems a little different from the way I put it.
However, it will be displayed.

Launch with py bottle2.py in the current folder

Current folder
├ ├ bottle2.py
└ views
    └ index.html

bottle.py was installed with pip, not in the folder above, but in the following location:

 C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Lib\site-packages

@route The following is a description of the decorator.

bottle.route

Decorator to install a route to the current default application.See Bottle.route() for details.

bottle.Bottle.route

Adapter to bind a function to a request URL.Example:

@app.route('/hello/<name>')
def hello(name):
    return'Hello%s'%name

Omitted below

Some of Python's general decorators include:
Please try to understand from around here.
About Python Decorators
12 Steps to Understand Python Decorators
Python I'm not scared!Decorator
Re-introduction to Python decorators~Remember decorators by type~


2022-09-30 17:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.