Open kirtibajaj opened 5 years ago
Bottle is what is called a Web Server Gateway Interface (WSGI) framework. Let's take a tour through the Internet.
python -m http.server
it will give you a link like localhost:8000
. If you open that in your browser it shows you a file and folder listingfacebook.com
is either your home page or a login page depending on whether you are logged in or not. The ability to show different HTML for the same URL could not be handled by a file system like web server. A dynamic server was needed./say/hello
in bottle, what you would do is:import bottle
app = bottle.Bottle()
@app.get('/say/hello')
def function_which_says_hello():
return 'hello'
app.run()
GET
the url /say/hello
, run the function function_which_returns_hello
What happens when you ask for a location(URL) like github.com/PyJaipur
, a program running on some computer controlled by the company github decides what HTML to send to you.
1) path = os.path.abspath(__file__)
What does __file__
in the above line do? Also, I read that abspth() returns an absolutized version of pathname "path". What does absolutized mean?
2) @app.route('/hello/<something>')
def index(something):
return template('<b>Hello My Name is {{something}}</b>', something = 'Shivank')
This is a snippet of @Shivank98 's code of server.py . There is no such page as hello/<something>
. Then where is this piece of code being implemented?
python server.py
, a variable called __file__
is created which holds the location of the file that you are running.C:\System\something\something\Desktop
in windows or /home/user
.../abc
or ./some/folder
where ..
means the folder before and .
means current../PyJaipur
can be made /home/user/PyJaipur
template
is being used and the HTML template is provided as the first argument. That's why there is no separate HTML file. If you run the server and go to the url /hello/arjoonn
that function will run.Does that answer your question?
Further reading( In the future when you have time, I fully recommend trying to read both documents fully. Lots of interesting stuff):
Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no dependencies other than the Python Standard Library.