Skip to content

取自Django的multipart/form-data表单数据解析模块,可直接用于uWSGI应用

Notifications You must be signed in to change notification settings

tengzhang/uWsgiFormDataParser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

代码直接取自Django,删除了其中对Django其他包和模块的依赖,并对部分代码添加了注释(注释会不断更新)。

例子:

#wsgi.py,定义uwsgi application

from multipartparser import MultiPartParser
from datastructures import ImmutableList
from files.uploadhandler import MemoryFileUploadHandler,\
    TemporaryFileUploadHandler

def parse_form_data(env):
    upload_handlers = ImmutableList(
        [MemoryFileUploadHandler(),TemporaryFileUploadHandler()],
        warning="You cannot alter upload handlers after the upload has been processed."
    )
    parser = MultiPartParser(env, upload_handlers)
    return parser.parse()

def application(env, sr):
    
    params = parse_form_data(env)
    
    print params
    
    sr("200 OK", [("Content-Type", "text/html")])
    
    return "OK"
uwsgi --module wsgi --http :80  #启动uwsgi服务器
#借助requests测试表单数据提交
import requests

params = {
    "msg": "hello,world"          
}

files = {'mfy': open('/root/jp.png', 'rb')}

requests.post("http://127.0.0.1", data=params, files=files)

About

取自Django的multipart/form-data表单数据解析模块,可直接用于uWSGI应用

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%