Comments (3)
- I think you are talking about server.py#L4.
- Python has a few inbuilt variables. When you run a file with
python server.py
, a variable called__file__
is created which holds the location of the file that you are running. - Paths in most operating systems start at some top level.
C:\System\something\something\Desktop
in windows or/home/user
. - Paths can also be relative like
../abc
or./some/folder
where..
means the folder before and.
means current. - these paths can be made absolute. For example
./PyJaipur
can be made/home/user/PyJaipur
- Python has a few inbuilt variables. When you run a file with
- This refers to these 3 lines
- That code can be safely removed as it's not relevant to the project.
- There, the function
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):
from pyjudge.
Bottle is what is called a Web Server Gateway Interface (WSGI) framework. Let's take a tour through the Internet.
- when people first discovered that you could transfer files between computers they did it like they did any other thing. Via foot. Someone wrote a file to a floppy disk and then walked/drove to a friend's house and delivered the floppy. This was called sneaker-net (if it was first done in India it might have been called chappal-net).
- When computer networks were invented, people did not have to walk over. This gave rise to a new problem. The people you were sharing your files with were no longer just your friends. It could be anyone in the world. They had no idea what was on your computer. Some way to list files was needed in addition to sending the file to the person on their request.
- A natural way was for people to be able to see inside someone's computer. Sort of a remote file explorer. Since during those times the command line was all that was popular, the obvious solution was a remote, text based file explorer.
- you can try this out yourself. If you have python 3 open a command line and go to some folder. When you do
python -m http.server
it will give you a link likelocalhost:8000
. If you open that in your browser it shows you a file and folder listing
- This was all very good if you only ever wanted to show the same things again and again (for example a HTTP based book).
- Things changed when things like facebook were designed (facebook was not the first).
facebook.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.- After a long evolution involving things like CGI/php etc, a neat solution called WSGI was created.
- What wsgi does is define a standard way to introduce this dynamic ability.
- when a user goes to a url, the full request that the user made is given to a function.
- That function must then return a valid HTTP response which is then returned to the user.
- Bottle makes this last part easier. For example, if you want to show 'hello' at the url
/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()
- First you create an app(application. This is needed by the WSGI system)
- You tell the app that whenever someone wants to
GET
the url/say/hello
, run the functionfunction_which_returns_hello
- The function returns a simple python string. Bottle realizes that this is not a proper HTTP response and builds a proper response from that string before returning it to the person who made the request
- finally you run the web server. Bottle has it's own web server for development purposes. You might have heard of others
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.
from pyjudge.
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?
@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?
from pyjudge.
Related Issues (20)
- Database HOT 1
- Contest timings HOT 2
- Home page HOT 5
- Multiple contests
- Multiple contest UI design
- Move pre-commit and black to dev dependencies
- Pip installable project HOT 11
- 404 handler HOT 2
- Proper question statement and support HOT 5
- Session support
- Use sqlite as a database
- Interface to add questions via website HOT 4
- Raise error in proper places HOT 5
- Use a more common template system HOT 5
- Continuous testing needs to be added
- User stats/ profile HOT 4
- problem status in contest
- Reinstall black HOT 1
- Code Documentaion HOT 1
- Install pytest in pipenv HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyjudge.