|
1 |
| -# Litefs: A Lite Python Web Framework |
2 |
| - |
3 |
| -Build a web server framework using Python. Litefs was developed to implement a server framework that can quickly, securely, and flexibly build Web projects. Litefs is a high-performance HTTP server. Litefs has the characteristics of high stability, rich functions, and low system consumption. |
4 |
| - |
5 |
| -## Installation |
6 |
| - |
7 |
| -It can be installed via pip: |
8 |
| - |
9 |
| - $ pip install litefs |
10 |
| - |
11 |
| -It can be installed via source code: |
12 |
| - |
13 |
| - $ git clone https://github.com/leafcoder/litefs.git litefs |
14 |
| - $ cd litefs |
15 |
| - $ python setup.py install |
16 |
| - |
17 |
| -## Quickstart: "Hello world" |
18 |
| - |
19 |
| -Firstly, let's write a basci example via litefs. Save it to "example.py". |
20 |
| - |
21 |
| - # /usr/bin/env python |
22 |
| - |
23 |
| - import litefs |
24 |
| - litefs.test_server() |
25 |
| - |
26 |
| -Secondly, you should create a directory named "site" (or any other name which is same as __"--webroot"__). |
27 |
| - |
28 |
| - $ mkdir ./site |
29 |
| - |
30 |
| -Thirdly, you can copy the below code into a new file "./site/helloworld.py". |
31 |
| - |
32 |
| - def handler(self): |
33 |
| - return "Hello World!" |
34 |
| - |
35 |
| -Run "example.py", visit "http://localhost:9090/helloworld" via your browser. You can see "Hello World!" in your browser. |
36 |
| - |
37 |
| - $ ./example.py |
38 |
| - Litefs 0.3.0 - January 15, 2020 - 10:46:39 |
39 |
| - Starting server at http://localhost:9090/ |
40 |
| - Quit the server with CONTROL-C. |
41 |
| - |
42 |
| -## Command Help |
43 |
| - |
44 |
| - $ ./example --help |
45 |
| - usage: example.py [-h] [--host HOST] [--port PORT] [--webroot WEBROOT] |
46 |
| - [--debug] [--not-found NOT_FOUND] |
47 |
| - [--default-page DEFAULT_PAGE] [--cgi-dir CGI_DIR] |
48 |
| - [--log LOG] [--listen LISTEN] |
49 |
| - |
50 |
| - Build a web server framework using Python. Litefs was developed to implement a |
51 |
| - server framework that can quickly, securely, and flexibly build Web projects. |
52 |
| - Litefs is a high-performance HTTP server. Litefs has the characteristics of |
53 |
| - high stability, rich functions, and low system consumption. Author: leafcoder |
54 |
| - Email: leafcoder@gmail.com Copyright (c) 2017, Leafcoder. License: MIT (see |
55 |
| - LICENSE for details) |
56 |
| - |
57 |
| - optional arguments: |
58 |
| - -h, --help show this help message and exit |
59 |
| - --host HOST bind server to HOST |
60 |
| - --port PORT bind server to PORT |
61 |
| - --webroot WEBROOT use WEBROOT as root directory |
62 |
| - --debug start server in debug mode |
63 |
| - --not-found NOT_FOUND |
64 |
| - use NOT_FOUND as 404 page |
65 |
| - --default-page DEFAULT_PAGE |
66 |
| - use DEFAULT_PAGE as web default page |
67 |
| - --cgi-dir CGI_DIR use CGI_DIR as cgi scripts directory |
68 |
| - --log LOG save log to LOG |
69 |
| - --listen LISTEN server LISTEN |
70 |
| - |
71 |
| - |
72 |
| -## Object "self " |
73 |
| - |
74 |
| -List attributes of "self". |
75 |
| - |
76 |
| -Attributes | Description |
77 |
| ----------------------------------------------------- | ----------- |
78 |
| -self.environ | 环境变量(只读) |
79 |
| -self.environ`[`_*envname*_`]` | 获取某环境变量 |
80 |
| -self.session | session 对象,可临时保存或获取内存数据 |
81 |
| -self.session_id | session 对象 ID,将通过 SET_COOKIE 环境变量返回给客户端浏览器 |
82 |
| -self.form | form 为字典对象,保存您提交到服务器的数据 |
83 |
| -self.config | 服务器的配置对象,可获取初始化服务器的配置信息 |
84 |
| -self.files | 字典对象,保存上传的文件,格式为:{ *filename1*: *\<StringIO object\>*, *filename2*: *\<StringIO object\>* } |
85 |
| -self.cookie | SimpleCookie 对象,获取 Cookie 数据 |
86 |
| -self.redirect(url=None) | 跳转到某一页面 |
87 |
| -self.start_response(status_code=200, headers=None) | HTTP 返回码和头部 |
88 |
| - |
89 |
| -## HTTP Headers in Environ |
90 |
| - |
91 |
| -环境变量 | 描述 | 例子 |
92 |
| -------------------- | --------------------- | ---- |
93 |
| -REQUEST_METHOD | 请求方法 | GET、POST、PUT、HEAD等 |
94 |
| -SERVER_PROTOCOL | 请求协议/版本 | HTTP/1.1" |
95 |
| -REMOTE_ADDR | 请求客户端的IP地址 | 192.168.1.5 |
96 |
| -REMOTE_PORT | 请求客户端的端口 | 9999 |
97 |
| -REQUEST_URI | 完整 uri | /user_info?name=li&age=20 |
98 |
| -PATH_INFO | 页面地址 | /user_info |
99 |
| -QUERY_STRING | 请求参数 | name=li&age=20 |
100 |
| -CONTENT_TYPE | POST 等报文类型 | application/x-www-form-urlencoded 或 text/html;charset=utf-8 |
101 |
| -CONTENT_LENGTH | POST 等报文长度 | 1024 |
102 |
| -HTTP_*_HEADERNAME_* | 其他请求头部 | 如 HTTP_REFERER:https://www.baidu.com/ |
103 |
| - |
104 |
| -## Get HTTP Header via "self" |
105 |
| - |
106 |
| -环境变量 | 对应属性 |
107 |
| ---------------- | ------- |
108 |
| -PATH_INFO | self.path_Info |
109 |
| -QUERY_STRING | self.query_string |
110 |
| -REQUEST_URI | self.request_uri |
111 |
| -REFERER | self.referer |
112 |
| -REQUEST_METHOD | self.request_method |
113 |
| -SERVER_PROTOCOL | self.server_protocol |
114 |
| - |
115 |
| -## Mako Template Page |
116 |
| - |
117 |
| -## CGI Script Page |
118 |
| - |
119 |
| -## Python Script Page |
120 |
| - |
121 |
| -## Static Files |
| 1 | +# Litefs |
| 2 | + |
| 3 | +Litefs is a lite python web framework. |
| 4 | + |
| 5 | +Build a web server framework using Python. Litefs was developed to implement |
| 6 | +a server framework that can quickly, securely, and flexibly build Web |
| 7 | +projects. Litefs is a high-performance HTTP server. Litefs has the |
| 8 | +characteristics of high stability, rich functions, and low system |
| 9 | +consumption. |
0 commit comments