Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bdabb16

Browse filesBrowse files
committed
docs: add docs
1 parent ea5346d commit bdabb16
Copy full SHA for bdabb16

File tree

Expand file treeCollapse file tree

4 files changed

+274
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+274
-0
lines changed

‎.gitignore

Copy file name to clipboardExpand all lines: .gitignore
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ __pycache__/
1414
*.pyc
1515
*.log
1616
.idea/
17+
docs/_book/
18+
docs/node_modules/

‎docs/SUMMARY.md

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Summary
2+
3+
* [Tutorial](tutorial.md)

‎docs/book.json

Copy file name to clipboard
+104Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"title": "Litefs",
3+
"description": "A Lite Python Web Framework",
4+
"author": "leafcoder",
5+
"output.name": "site",
6+
"language": "zh-hans",
7+
"gitbook": "3.2.2",
8+
"root": ".",
9+
"structure": {
10+
"readme": "tutorial.md"
11+
},
12+
"plugins": [
13+
"-lunr",
14+
"-search",
15+
"-highlight",
16+
"-livereload",
17+
"search-plus@^0.0.11",
18+
"simple-page-toc@^0.1.1",
19+
"github@^2.0.0",
20+
"github-buttons@2.1.0",
21+
"prism@^2.1.0",
22+
"prism-themes@^0.0.2",
23+
"advanced-emoji@^0.2.1",
24+
"anchors@^0.7.1",
25+
"include-codeblock@^3.0.2",
26+
"ace@^0.3.2",
27+
"emphasize@^1.1.0",
28+
"katex@^1.1.3",
29+
"splitter@^0.0.8",
30+
"tbfed-pagefooter@^0.0.1",
31+
"expandable-chapters-small@^0.1.7",
32+
"sectionx@^3.1.0",
33+
"local-video@^1.0.1",
34+
"anchor-navigation-ex@0.1.8",
35+
"favicon@^0.0.2",
36+
"todo@^0.1.3",
37+
"3-ba@^0.9.0"
38+
],
39+
"pluginsConfig": {
40+
"theme-default": {
41+
"showLevel": true
42+
},
43+
"prism": {
44+
"css": [
45+
"prism-themes/themes/prism-base16-ateliersulphurpool.light.css"
46+
]
47+
},
48+
"github": {
49+
"url": "https://github.com/leafcoder/litefs"
50+
},
51+
"github-buttons": {
52+
"repo": "leafcoder/litefs",
53+
"types": [
54+
"star"
55+
],
56+
"size": "small"
57+
},
58+
"include-codeblock": {
59+
"template": "ace",
60+
"unindent": true,
61+
"edit": true
62+
},
63+
"sharing": {
64+
"weibo": true,
65+
"facebook": true,
66+
"twitter": true,
67+
"google": false,
68+
"instapaper": false,
69+
"vk": false,
70+
"all": [
71+
"facebook",
72+
"google",
73+
"twitter",
74+
"weibo",
75+
"instapaper"
76+
]
77+
},
78+
"tbfed-pagefooter": {
79+
"copyright": "Copyright © leafcoder 2020",
80+
"modify_label": "该文件修订时间:",
81+
"modify_format": "YYYY-MM-DD HH:mm:ss"
82+
},
83+
"3-ba": {
84+
"token": "xxx"
85+
},
86+
"simple-page-toc": {
87+
"maxDepth": 3,
88+
"skipFirstH1": true
89+
},
90+
"anchor-navigation-ex": {
91+
"isRewritePageTitle": false,
92+
"tocLevel1Icon": "fa fa-hand-o-right",
93+
"tocLevel2Icon": "fa fa-hand-o-right",
94+
"tocLevel3Icon": "fa fa-hand-o-right"
95+
},
96+
"sectionx": {
97+
"tag": "b"
98+
},
99+
"favicon": {
100+
"shortcut": "favicon.ico",
101+
"bookmark": "favicon.ico"
102+
}
103+
}
104+
}

‎docs/tutorial.md

Copy file name to clipboard
+165Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Introduction
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.
10+
11+
# Installation
12+
13+
It can be installed via pip:
14+
15+
$ pip install litefs
16+
17+
It can be installed via source code:
18+
19+
$ git clone https://github.com/leafcoder/litefs.git litefs
20+
$ cd litefs
21+
$ python setup.py install
22+
23+
# Quickstart: "Hello world"
24+
25+
Firstly, let's write a basci example via litefs. Save it to "example.py".
26+
27+
# /usr/bin/env python
28+
29+
import litefs
30+
litefs.test_server()
31+
32+
Secondly, you should create a directory named "site" (or any other name
33+
which is same as __"--webroot"__).
34+
35+
$ mkdir ./site
36+
37+
Thirdly, you can copy the below code into a new file "./site/helloworld.py".
38+
39+
def handler(self):
40+
return "Hello World!"
41+
42+
Run "example.py", visit "http://localhost:9090/helloworld" via your browser.
43+
You can see "Hello World!" in your browser.
44+
45+
$ ./example.py
46+
Litefs 0.3.0 - January 15, 2020 - 10:46:39
47+
Starting server at http://localhost:9090/
48+
Quit the server with CONTROL-C.
49+
50+
# URL ROUTES
51+
52+
The relative path of the python scripts in the "site" folder will be url routes.
53+
54+
For example, we create tow files in "site" folder like below.
55+
56+
## Script route
57+
# Python route
58+
# ./site/hello.py => matches /hello
59+
def handler(self):
60+
return 'Hello world'
61+
62+
## Template route
63+
64+
Note: "http" means "self" in handler function.
65+
66+
# Template route
67+
# ./site/cn/hello.mako => matches /cn/hello
68+
<pre>
69+
PATH_INFO : ${http.path_info}
70+
QUERY_STRING: ${http.query_string}
71+
REQUEST_URI : ${http.request_uri}
72+
REFERER : ${http.referer}
73+
COOKIE : ${http.cookie}
74+
75+
hello world
76+
</pre>
77+
78+
## Static file
79+
80+
# Other static route => matches /hello.txt
81+
# ./site/hello.txt
82+
Hello world
83+
84+
# HTTP Methods
85+
86+
Litefs handlers all methods such as GET, POST, PUT, DELETE or PATCH in
87+
"handler" function.
88+
89+
def handler(self):
90+
request_method = self.request_method
91+
logger.info(request_method)
92+
return 'request_method: %s' % request_method
93+
94+
# Error Pages
95+
96+
You can set a default 404 page when you start a litefs server.
97+
98+
$ ./example.py --not-found=not_found.html
99+
100+
# Help
101+
102+
$ ./example.py --help
103+
usage: example.py [-h] [--host HOST] [--port PORT] [--webroot WEBROOT]
104+
[--debug] [--not-found NOT_FOUND]
105+
[--default-page DEFAULT_PAGE] [--cgi-dir CGI_DIR]
106+
[--log LOG] [--listen LISTEN]
107+
108+
Build a web server framework using Python. Litefs was developed to implement a
109+
server framework that can quickly, securely, and flexibly build Web projects.
110+
Litefs is a high-performance HTTP server. Litefs has the characteristics of
111+
high stability, rich functions, and low system consumption. Author: leafcoder
112+
Email: leafcoder@gmail.com Copyright (c) 2017, Leafcoder. License: MIT (see
113+
LICENSE for details)
114+
115+
optional arguments:
116+
-h, --help show this help message and exit
117+
--host HOST bind server to HOST
118+
--port PORT bind server to PORT
119+
--webroot WEBROOT use WEBROOT as root directory
120+
--debug start server in debug mode
121+
--not-found NOT_FOUND
122+
use NOT_FOUND as 404 page
123+
--default-page DEFAULT_PAGE
124+
use DEFAULT_PAGE as web default page
125+
--cgi-dir CGI_DIR use CGI_DIR as cgi scripts directory
126+
--log LOG save log to LOG
127+
--listen LISTEN server LISTEN
128+
129+
130+
## Context
131+
132+
List attributes of "self".
133+
134+
Attributes | Description
135+
---------------------------------------------------- | -----------
136+
self.environ | 环境变量(只读)
137+
self.environ`[`_*envname*_`]` | 获取某环境变量
138+
self.session | session 对象,可临时保存或获取内存数据
139+
self.session_id | session 对象 ID,将通过 SET_COOKIE 环境变量返回给客户端浏览器
140+
self.form | form 为字典对象,保存您提交到服务器的数据
141+
self.config | 服务器的配置对象,可获取初始化服务器的配置信息
142+
self.files | 字典对象,保存上传的文件,格式为:{ *filename1*: *\<StringIO object\>*, *filename2*: *\<StringIO object\>* }
143+
self.cookie | SimpleCookie 对象,获取 Cookie 数据
144+
self.redirect(url=None) | 跳转到某一页面
145+
self.start_response(status_code=200, headers=None) | HTTP 返回码和头部
146+
self.path_Info | PATH_INFO
147+
self.query_string | QUERY_STRING
148+
self.request_uri | REQUEST_URI
149+
self.referer | REFERER
150+
self.request_method | REQUEST_METHOD
151+
self.server_protocol | SERVER_PROTOCOL
152+
## Environ
153+
154+
环境变量 | 描述 | 例子
155+
------------------- | --------------------- | ----
156+
REQUEST_METHOD | 请求方法 | GET、POST、PUT、HEAD等
157+
SERVER_PROTOCOL | 请求协议/版本 | HTTP/1.1"
158+
REMOTE_ADDR | 请求客户端的IP地址 | 192.168.1.5
159+
REMOTE_PORT | 请求客户端的端口 | 9999
160+
REQUEST_URI | 完整 uri | /user_info?name=li&age=20
161+
PATH_INFO | 页面地址 | /user_info
162+
QUERY_STRING | 请求参数 | name=li&age=20
163+
CONTENT_TYPE | POST 等报文类型 | application/x-www-form-urlencoded 或 text/html;charset=utf-8
164+
CONTENT_LENGTH | POST 等报文长度 | 1024
165+
HTTP_*_HEADERNAME_* | 其他请求头部 | 如 HTTP_REFERER:https://www.baidu.com/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.