Quick Start "Hello world!"
This tutorial assumes that you have installed bottle or have copied it to your project directory. Let's take a look at this very basic example of "helloWorld":
from Import route, Run@route ('/hello') def Hello (): return " Hello world! " Run (Host='localhost', port=8080, Debug=true)
Run this script, Access Http://localhost:8080/hello then you can see "Hello World" in your traffic, here's how he works:
route () modifier in URL /hello path to access hello () function. It is called a route ( ) Span style= "font-family: the song Body;" > This is the most important concept in this framework. You want to define how much routes You can define how much. When a browser goes to request a url The associated function is called and the return value is sent to a browser. It's so simple!
Run () is called on the last line to start a built-in development server. The server runs on the 8080 port on localhost and accepts the request until it is stopped using Ctrl + C . You can replace the backend server later, but now this development server is enough for us to use. It does not need to be installed at all and can be very laborious for your program to start running for local testing.
Debug mode is useful in the early stages of development, but remember to turn off debug mode when you publish your program .
This is a very simple procedure, of course, and he shows a basic concept of how to build a program on bottle. Read on and you'll see more of the other possibilities.
If there is any fallacy please point out, thank you! We learn together, reproduced the source of the specified!
Bottle Developer Chinese Document (2)--Quick Start "Hello world!"