current position:Home>python wsgi
python wsgi
2022-02-01 20:05:29 【waws520】
wsgi
wsgi The full name is "Web Server Gateway Interfacfe",web Server gateway interface ,wsgi stay python2.5 Add , yes web The server
and web Application standard interface
, Any that implements the interface web The server and web Applications can work seamlessly . Look at a picture of image points :
As shown in the figure above ,wsgi One end is connected to web The server (http The server ), Connect the application at the other end . There are already many web frame , Such as flask、webpy, Users simply configure some routing information , You can develop one web application . In the following text web Framework is equivalent to application (application)
So what does this interface look like ,pep333 That's how it's described :
(1)App Provide a that accepts two parameters callable object . The first parameter is a dict type , Represents the environment variable associated with the request ; The second parameter is a callable object ,app Call this in code callable Set the message header of the response .app You need to return an iteratable string sequence , Indicates the message content of the response
(2)web server stay http When the request comes , call App Provided callable object , The parameters of the incoming response . And then put App Send the return value of to http Requestor ( Such as browser )
First , Let's look at the most basic example ,wsgi Of Hello World!
def hello_world_app(environ, start_response):
status = '200 OK' # HTTP Status
headers = [('Content-type', 'text/plain')] # HTTP Headers
start_response(status, headers)
# The returned object is going to be printed
return ["Hello World"]
Copy code
Of course , We need to web The server can test this App,python Provides a pure python It's simple web The server :wsgiref. This implementation is single threaded , The performance is not very good , But it can be used for testing .
def hello_world_app(environ, start_response):
status = '200 OK' # HTTP Status
headers = [('Content-type', 'text/plain')] # HTTP Headers
start_response(status, headers)
# The returned object is going to be printed
return ["Hello World"]
def main():
from wsgiref.simple_server import make_server
httpd = make_server('', 8000, hello_world_app)
print "Serving on port 8000..."
# Serve until process is killed
httpd.serve_forever()
if __name__ == '__main__':
main()
Copy code
Run this code , Then type in the browser 127.0.0.1:8000, You can see the result
common python web The server includes ,
cherrypy
、gevent-fastcgi
、gunicorn
、uwsgi
、twisted
、webpy
、tornado
wait , in application , these web The server may need to cooperate with other servers http Proxy use , Such as Nginx.common python web The framework includes
Django
,Flask
, webpy,bottle,Cherrypy,tornado
. some web The framework itself comes with web The server , Such as Cherrypy、tornado.tornado Because there are asynchronous network libraries , As web The server performance is also good .
Last , Recommend an article Let’s Build A Web Server. The article consists of three parts : Part I Introduction http service ; The second part implements a wsgi web The server , And cooperate with various web The framework is used and tested ; The third part realizes the second part wsgi The server is optimized for concurrency .
copyright notice
author[waws520],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202012005199227.html
The sidebar is recommended
- Python data analysis - linear regression selection fund
- How to make a python SDK and upload and download private servers
- Python from 0 to 1 (day 20) - basic concepts of Python dictionary
- Django -- closure decorator regular expression
- Implementation of home page and back end of Vue + Django tourism network project
- Easy to use scaffold in Python
- [Python actual combat sharing] I wrote a GIF generation tool, which is really TM simple (Douluo continent, did you see it?)
- [Python] function decorators and common decorators
- Explain the python streamlit framework in detail, which is used to build a beautiful data visualization web app, and practice making a garbage classification app
- Construction of the first Django project
guess what you like
-
Python crawler actual combat, pyecharts module, python realizes the visualization of river review data
-
Python series -- web crawler
-
Plotly + pandas + sklearn: shoot the first shot of kaggle
-
How to learn Python systematically?
-
Analysis on several implementations of Python crawler data De duplication
-
leetcode 1616. Split Two Strings to Make Palindrome (python)
-
Python Matplotlib drawing violin diagram
-
Python crawls a large number of beautiful pictures with 10 lines of code
-
[tool] integrated use of firebase push function in Python project
-
How to use Python to statistically analyze access logs?
Random recommended
- How IOS developers learn Python Programming 22 - Supplement 1
- Python can meet any API you need
- Python 3 process control statement
- The 20th of 120 Python crawlers, 1637. All the way business opportunity network joined in data collection
- Datetime of pandas time series preamble
- How to send payslips in Python
- [Python] closure and scope
- Application of Python Matplotlib color
- leetcode 1627. Graph Connectivity With Threshold (python)
- Python thread 08 uses queues to transform the transfer scenario
- Python: simple single player strange game (text)
- Daily python, chapter 27, Django template
- TCP / UDP communication based on Python socket
- Use of pandas timestamp index
- leetcode 148. Sort List(python)
- Confucius old book network data collection, take one anti three learning crawler, python crawler 120 cases, the 21st case
- [HTB] cap (datagram analysis, setuid capability: Python)
- How IOS developers learn Python Programming 23 - Supplement 2
- How to automatically identify n + 1 queries in Django applications (2)?
- Data analysis starts from scratch. Pandas reads HTML pages + data processing and analysis
- 1313. Unzip the coding list (Java / C / C + + / Python / go / trust)
- Python Office - Python edit word
- Collect it quickly so that you can use the 30 Python tips for taking off
- Strange Python strip
- Python crawler actual combat, pyecharts module, python realizes China Metro data visualization
- DOM breakpoint of Python crawler reverse
- Django admin custom field stores links in the database after uploading files to the cloud
- Who has powder? Just climb who! If he has too much powder, climb him! Python multi-threaded collection of 260000 + fan data
- Python Matplotlib drawing streamline diagram
- The game comprehensively "invades" life: Python releases the "cool run +" plan!
- Python crawler notes: use proxy to prevent local IP from being blocked
- Python batch PPT to picture, PDF to picture, word to picture script
- Advanced face detection: use Dlib, opencv and python to detect face markers
- "Python 3 web crawler development practice (Second Edition)" is finally here!!!!
- Python and Bloom filters
- Python - singleton pattern of software design pattern
- Lazy listening network, audio novel category data collection, multi-threaded fast mining cases, 23 of 120 Python crawlers
- Troubleshooting ideas and summary of Django connecting redis cluster
- Python interface automation test framework (tools) -- interface test tool requests
- Implementation of Morse cipher translator using Python program