码迷,mamicode.com
首页 > 编程语言 > 详细

how to setup nginx + uwsgi + bottle for RESTful python framework

时间:2017-05-11 14:28:32      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:nic   ret   params   .com   sts   bre   view   path   lan   

how to setup nginx + uwsgi + bottle for RESTful python framework

  1. install necessary modules
  1. yaourt -S uwsgi uwsgi-plugin-python python-bottle 
  1. setup nginx
    llwang@ASMC~ $ cat /etc/nginx/conf.d/my.conf
  1. server { 
  2. listen 9000; 
  3. server_name 45.63.49.131; 
  4.  
  5. # Path to the root of your installation 
  6. root /srv/http/my/; 
  7.  
  8. location / { 
  9. include uwsgi_params; 
  10. uwsgi_pass 127.0.0.1:9090; 


  1. write python code
    llwang@ASMC~ $ cat /srv/http/my/hello.py
  1. from bottle import route, default_app, request, post 
  2. @route(‘/‘) 
  3. def hello(): 
  4. return ‘hello world!‘ 
  5.  
  6. upload_path=‘./static‘#定义上传文件的保存路径 
  7. @route(‘/upload‘,method=‘POST‘) 
  8. def do_upload(): 
  9. uploadfile=request.files.get(‘data‘) #获取上传的文件 
  10. uploadfile.save(upload_path,overwrite=True)#overwrite参数是指覆盖同名文件 
  11. return u"上传成功,文件名为:%s,文件类型为:%s"% (uploadfile.filename,uploadfile.content_type) 
  12. #filename是获取上传文件文件名,content_type是获取上传的文件类型 
  13.  
  14.  
  15. application = default_app() 
  1. setup uwsgi
  1. uwsgi --plugin python -s 127.0.0.1:9090 -w hello 
  1. visit web from python script
  1. #!/usr/bin/python 
  2.  
  3. import requests 
  4.  
  5. url=‘http://45.63.49.131:9000/upload‘ 
  6.  
  7. files = {‘data‘: open(‘dwm_config.h‘, ‘rb‘)} 
  8. r = requests.post(url,files=files) 
  9. print(r.text) 
  10.  

2017-5-9 nicephil@gmail.com

how to setup nginx + uwsgi + bottle for RESTful python framework

标签:nic   ret   params   .com   sts   bre   view   path   lan   

原文地址:http://www.cnblogs.com/nicephil/p/6840500.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!