How does python write the website background without a framework?

Source: Internet
Author: User
How does python write the website background without the framework? How does python write the website background reply content without the framework? The basehttpserver In the python standard library is suitable for you, after reading the source code, you will know that the Django translation document contains the following paragraph:

If you have compiled a network application. Then you are likely to be familiar with our CGI example.
Write network applications from scratch.
Write another network application from scratch.
Summarize from the first step (find out the common code) and apply it to the second step.
Refactoring Code enables the use of common code from 2nd programs in 1st programs.
Repeat steps 2-4 several times.
Realize that you have invented a framework.
That's why Django was created!

You don't need to implement the Framework at the end of the Framework, right. Why do we need to repeat the wheel? Of course, if it is to upgrade the carriage into a car, it is not to create a wheel.
Let's take a look at Liao Xuefeng's tutorial, which is his own framework. We also recommend the Python tutorial for routine examples-liao Xuefeng's official website. Don't say that you can read this write function without using the framework. You can even write it after reading Python. Look at this A Do-It-Yourself Framework. You can try to use WSGI, similar to Java servlet, but define a set of Interface specifications for the framework to interact with the Server. For details, refer to PEP 333 -- Python Web Server Gateway Interface v1.0.

The simplest application is as follows:

def simple_app(environ, start_response):    status = '200 OK'    response_headers = [('Content-type', 'text/plain')]    start_response(status, response_headers)    return ['Hello world!\n']
Python comes with a CGI library called cgi.

Similar to the perl website written decades ago. You need to process the session, cookie, and URL routing by yourself.

Performance is also not good: Each http request corresponds to a python script.

If you want to learn more, do not abuse yourself. PHP can do this because in addition to the language, PHP also has a web framework that comes with the language (which language has seen functions similar to session_start ?) Isn't the flask, bottle, tornado microframework working?
What about werkzeug?
For example, uwsgi + werkzeug + implements wsgi application
Isn't flask the wsgi application that wraps werkzeug?
Add a database module or session module specified on demand.

If werkzeug is too big, there are a lot of things to implement. http parsing, url parsing, url route, and so on, isn't it a bit difficult to figure out CGI? You can implement wsgi,... Do you really don't need a framework? Why don't you need a framework? Sooner or later, you will write a framework yourself.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.