首页 > 代码库 > how to setup nginx + uwsgi + bottle for RESTful python framework
how to setup nginx + uwsgi + bottle for RESTful python framework
how to setup nginx + uwsgi + bottle for RESTful python framework
python
- install necessary modules
- yaourt -S uwsgi uwsgi-plugin-python python-bottle
- setup nginx
llwang@ASMC~ $ cat /etc/nginx/conf.d/my.conf
- server {
- listen 9000;
- server_name 45.63.49.131;
-
- # Path to the root of your installation
- root /srv/http/my/;
-
- location / {
- include uwsgi_params;
- uwsgi_pass 127.0.0.1:9090;
- }
- }
- write python code
llwang@ASMC~ $ cat /srv/http/my/hello.py
- from bottle import route, default_app, request, post
- def hello():
- return ‘hello world!‘
-
- upload_path=‘./static‘#定义上传文件的保存路径
- def do_upload():
- uploadfile=request.files.get(‘data‘) #获取上传的文件
- uploadfile.save(upload_path,overwrite=True)#overwrite参数是指覆盖同名文件
- return u"上传成功,文件名为:%s,文件类型为:%s"% (uploadfile.filename,uploadfile.content_type)
- #filename是获取上传文件文件名,content_type是获取上传的文件类型
-
-
- application = default_app()
- setup uwsgi
- uwsgi --plugin python -s 127.0.0.1:9090 -w hello
- visit web from python script
- #!/usr/bin/python
-
- import requests
-
- url=‘http://45.63.49.131:9000/upload‘
-
- files = {‘data‘: open(‘dwm_config.h‘, ‘rb‘)}
- r = requests.post(url,files=files)
- print(r.text)
-
2017-5-9 nicephil@gmail.com
how to setup nginx + uwsgi + bottle for RESTful python framework
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。