Pyramid It's more popular Python Web frame , More flexible , It's also powerful . In recent projects , I plan to study . There are few online tutorials , And a lot of them are aimed at linux Platform , I am a windows The natives, so for those linux How do commands translate into windows Orders are a headache . Took time to learn , To maximize the value of time , Share it to help you save your study time .
The main learning materials are from the official website , Address the following ：
All orders are directed at windows platform
Python development tool ：VS Code
Let's start from building pyramid Let's start with our first service .
1. Create an empty folder for the new project D:\Python_project\ms_study
2. Create a virtual environment for the project .D:\python_virtual\ms_study
Knowledge point 【 A virtual environment 】： because python The project references a lot of packages , Each project calls a different package , Generate some compiled files , Therefore, each project can have its own virtual compilation environment , It can isolate projects .
command ：virtualenv Virtual environment directory name
3. Activate the virtual environment , Enter the virtual environment Directory D:\python_virtual\ms_study\Scripts, And use activate Command to activate . Install after activation pyramid package .
pip install pyramid
4. Choose the compilation environment ： stay VS Code The lower left corner is shown in the picture Python 3.8.5 64-bit Click here to select the compiler tool , Here we choose the newly created virtual environment ：d:\\python_virtual\\ms_study\\Scripts\\python.exe.
5. stay D:\Python_project\ms_study Under the new python File and add the code as follows ：
Knowledge point ：
1）configurator yes pyramid A very important class , It's a context management tool , Used to connect attempts and routes .
2）make_wsgi_app: Establish a compliance wsgi Agreed web application
3）make_server To establish web service
4）server.serve_forever You can make this web The service runs until your program is shut down
5） python use with as Statement operation context manager , Automatically allocate and release resources . amount to c# Inside using()
6. Click on F5 Choose the top one Python File