|
1 |
| - |
2 |
| -# 1. 快速启动 |
3 |
| - |
4 |
| -1.1 启动脚本 |
5 |
| ---------------- |
6 |
| - |
7 |
| - import sys |
8 |
| - sys.dont_write_bytecode = True |
9 |
| - |
10 |
| - import litefs |
11 |
| - litefs = litefs.Litefs( |
12 |
| - address='0.0.0.0:8080', webroot='./site', debug=True |
13 |
| - ) |
14 |
| - litefs.run(timeout=2.) |
15 |
| - |
16 |
| -将上面的代码保存为 run.py 文件。 |
17 |
| - |
18 |
| -1.2 页面脚本 |
19 |
| ---------------- |
20 |
| - |
21 |
| -在网站目录(注:启动脚本中 webroot 的目录)中,添加一个后缀名为 **.py** 的文件,如 example.py,代码如下: |
22 |
| - |
23 |
| - def handler(self): |
24 |
| - self.start_response(200, headers=[]) |
25 |
| - return 'Hello world!' |
26 |
| - |
27 |
| - or |
28 |
| - |
29 |
| - def handler(self): |
30 |
| - return 'Hello world!' |
31 |
| - |
32 |
| -1.3 启动网站 |
33 |
| ------------ |
34 |
| - |
35 |
| - $ python run.py |
36 |
| - Server is running at 0.0.0.0:8080 |
37 |
| - Hit Ctrl-C to quit. |
38 |
| - |
39 |
| -运行启动脚本后,访问 http://0.0.0.0:8080/example,您会看到 `Hello world!`。 |
40 |
| - |
41 |
| - |
42 |
| -# 2. CGI 规则 |
43 |
| - |
44 |
| -2.1 httpfile 对象是服务器上下文接口,接口如下: |
45 |
| --------------------------------------- |
46 |
| - |
47 |
| -接口类型 | 接口使用 | 接口描述 |
48 |
| ----- | --- | ---- |
49 |
| -环境变量(只读) | httpfile.environ | 环境变量 |
50 |
| -某环境变量 | httpfile.environ`[`_*envname*_`]` | 获取某环境变量 |
51 |
| -Session | httpfile.session | session 对象,可临时保存或获取内存数据 |
52 |
| -Session ID | httpfile.session_id | session 对象 ID,将通过 SET_COOKIE 环境变量返回给客户端浏览器 |
53 |
| -Form | httpfile.form | form 为字典对象,保存您提交到服务器的数据 |
54 |
| -Config | httpfile.config | 服务器的配置对象,可获取初始化服务器的配置信息 |
55 |
| -files | httpfile.files | 字典对象,保存上传的文件,格式为:{ *filename1*: *\<StringIO object\>*, *filename2*: *\<StringIO object\>* } |
56 |
| -cookie | httpfile.cookie | SimpleCookie 对象,获取 Cookie 数据 |
57 |
| -页面跳转 | httpfile.redirect(url=None) | 跳转到某一页面 |
58 |
| -HTTP头部 | httpfile.start_response(status_code=200, headers=None) | HTTP 返回码和头部 |
59 |
| - |
60 |
| -2.2 以下为 httpfile 对象中环境变量(environ)包含的变量对应表 |
61 |
| ---------------------------------------------------- |
62 |
| - |
63 |
| -环境变量 | 描述 | 例子 |
64 |
| -------- | ------ | ---- |
65 |
| -REQUEST_METHOD | 请求方法 | GET、POST、PUT、HEAD等 |
66 |
| -SERVER_PROTOCOL | 请求协议/版本 | HTTP/1.1" |
67 |
| -REMOTE_ADDR | 请求客户端的IP地址 | 192.168.1.5 |
68 |
| -REMOTE_PORT | 请求客户端的端口 | 9999 |
69 |
| -REQUEST_URI | 完整 uri | /user_info?name=li&age=20 |
70 |
| -PATH_INFO | 页面地址 | /user_info |
71 |
| -QUERY_STRING | 请求参数 | name=li&age=20 |
72 |
| -CONTENT_TYPE | POST 等报文类型 | application/x-www-form-urlencoded 或 text/html;charset=utf-8 |
73 |
| -CONTENT_LENGTH | POST 等报文长度 | 1024 |
74 |
| -HTTP_*_HEADERNAME_* | 其他请求头部 | 如 HTTP_REFERER:https://www.baidu.com/ |
75 |
| - |
76 |
| -2.3 部分环境变量也可以使用 httpfile 属性的方式获取 |
77 |
| ------------------------------------------- |
78 |
| - |
79 |
| -环境变量 | 对应属性 |
80 |
| -------- | ------- |
81 |
| -PATH_INFO | httpfile.path_Info |
82 |
| -QUERY_STRING | httpfile.query_string |
83 |
| -REQUEST_URI | httpfile.request_uri |
84 |
| -REFERER | httpfile.referer |
85 |
| -REQUEST_METHOD | httpfile.request_method |
86 |
| -SERVER_PROTOCOL | httpfile.server_protocol |
87 |
| - |
88 |
| -# 3. Mako 文件支持 |
89 |
| - |
90 |
| -TODO |
91 |
| - |
92 |
| -# 4. CGI 支持 |
93 |
| - |
94 |
| -TODO |
| 1 | +<div align="center"> |
| 2 | + |
| 3 | +# Litefs |
| 4 | + |
| 5 | +<p> |
| 6 | + <!-- Place this tag where you want the button to render. --> |
| 7 | + <a class="github-button" href="https://github.com/leafcoder/litefs/subscription" data-color-scheme="no-preference: light; light: light; dark: dark;" data-show-count="true" aria-label="Watch leafcoder/litefs on GitHub"> |
| 8 | + <img alt="GitHub forks" src="https://img.shields.io/github/watchers/leafcoder/litefs?style=social"> |
| 9 | + </a> |
| 10 | + <a class="github-button" href="https://github.com/leafcoder/litefs" data-color-scheme="no-preference: light; light: light; dark: dark;" data-show-count="true" aria-label="Star leafcoder/litefs on GitHub"> |
| 11 | + <img alt="GitHub forks" src="https://img.shields.io/github/stars/leafcoder/litefs?style=social"> |
| 12 | + </a> |
| 13 | + <a class="github-button" href="https://github.com/leafcoder/litefs/fork" data-color-scheme="no-preference: light; light: light; dark: dark;" data-show-count="true" aria-label="Fork leafcoder/litefs on GitHub"> |
| 14 | + <img alt="GitHub forks" src="https://img.shields.io/github/forks/leafcoder/litefs?style=social"> |
| 15 | + </a> |
| 16 | +</p> |
| 17 | + |
| 18 | +<p> |
| 19 | + <img src="https://img.shields.io/github/v/release/leafcoder/litefs" data-origin="https://img.shields.io/github/v/release/leafcoder/litefs" alt="GitHub release (latest by date)"> |
| 20 | + <img src="https://img.shields.io/github/languages/top/leafcoder/litefs" data-origin="https://img.shields.io/github/languages/top/leafcoder/litefs" alt="GitHub top language"> |
| 21 | + <img src="https://img.shields.io/github/languages/code-size/leafcoder/litefs" data-origin="https://img.shields.io/github/languages/code-size/leafcoder/litefs" alt="GitHub code size in bytes"> |
| 22 | + <img src="https://img.shields.io/github/commit-activity/w/leafcoder/litefs" data-origin="https://img.shields.io/github/commit-activity/w/leafcoder/litefs" alt="GitHub commit activity"> |
| 23 | + <img src="https://img.shields.io/github/downloads/leafcoder/litefs/total" data-origin="https://img.shields.io/github/downloads/leafcoder/litefs/total" alt="GitHub All Releases"> |
| 24 | +</p> |
| 25 | + |
| 26 | +</div> |
| 27 | + |
| 28 | +Litefs is a lite python web framework. |
| 29 | + |
| 30 | +Build a web server framework using Python. Litefs was developed to implement |
| 31 | +a server framework that can quickly, securely, and flexibly build Web |
| 32 | +projects. Litefs is a high-performance HTTP server. Litefs has the |
| 33 | +characteristics of high stability, rich functions, and low system |
| 34 | +consumption. |
0 commit comments