1. Environment
Windows 7 x64
IIS 6
Python 2.7.9
wfastcgi-3.0.0
flask-0.12.2
2, install wfastcgi, and start wfastcgi
Pip Install wfastcgi
C:\users\wangpan>d:\software\python27\scripts\wfastcgi-enable.exe
Configuration changes have been applied to the "system.webserver/fastcgi" section of "Machine/webroot/apphost" in the Configuration submission path "Machine/webroot/apphost"
"D:\software\python27\python.exe|d:\software\python27\lib\site-packages\wfastcgi.pyc" can now is used as a FastCGI Script processor
3, installation Flask
Pip Install flask
4. Open Windows features, install IIS, enable CGI
650) this.width=650; "src=" Http://jbcdn2.b0.upaiyun.com/2017/04/437b9614cffd92bd8585ff40532c71f8.png "style=" Border:0px;vertical-align:middle;height:auto; "alt=" 437b9614cffd92bd8585ff40532c71f8.png "/>
5. Install URL rewrite
IIS needs to install the URL rewrite component, which can be installed through Microsoft Web Platform Installer. After you download Microsoft Web Platform Installer, run the search URL and install the URL rewriting tool.
650) this.width=650; "class=" Alignnone wp-image-883 size-full "src=" https://10.12.49.221/wp-content/uploads/2017/08 /url%e9%87%8d%e5%86%99%e5%b7%a5%e5%85%b7%e5%ae%89%e8%a3%85.png "width=" 907 "height=" 617 "style=" border:0px; Vertical-align:middle;height:auto; "/>
6, configure IIS6.1 add website, root directory is d:\data\mysite\upload
650) this.width=650; "class=" Alignnone wp-image-884 size-large "src=" https://10.12.49.221/wp-content/uploads/2017/ 08/iis%e6%b7%bb%e5%8a%a0%e7%bd%91%e7%ab%99-1024x540.png "width=" 640 "height=" 338 "style=" border:0px; Vertical-align:middle;height:auto; "/>
6.2 D:\data\mysite\upload Directory Structure
Upload
–static static file directory for uploading directories
–upload.py Upload File Program
–web.config configuration file
6.3 Upload directory Web. config content
<?xml version= "1.0" encoding= "UTF-8"? > <configuration> <system.webserver > Attention:
ScriptProcessor content is the output of executing wfastcgi-enable
The value of Wsgi_handler
The value of Pythonpath
Wsgi_log's catalogue must exist.
6.4 upload.py The code to upload the file
#_ *_coding:utf-8_*_import osfrom flask import flask, request, redirect, url _for,render_templatefrom werkzeug import secure_filenamefrom flask import send_ from_directoryupload_folder = ' d:\data\mysite\upload\static ' allowed_extensions = set ([' txt ', ' docx ', ' Doc ', ' xlsx ' , ' xls ', ' ppt ' , ' pdf ', ' png ', ' jpg ', ' JPEG ', ' gif '] app = flask (__name__) app.config[' Upload_folder '] = upload_ Folderdef allowed_file (filename): return '. ' in filename and Filename.rsplit ('. ', 1) [1] in allowed_extensions@app.route ('/', methods=[' GET ', ' POST ']) def upload_file (): if request.method == ' POST ': file = request.files[' File '] filename = file.filename if file and allowed_file (filename): #filename = secure_filename (file.filename) file.save (Os.path.join (app.config[' UPLOAD_FOLDER ') , filename)) return redirect ( Url_for (' Uploaded_file ', filename=filename)) #return redirect (' success.html ') return ' < !doctype html> <title>upload new file</title> 7. Flask Learning Websitehttp://docs.jinkan.org/docs/flask/
This article is from the "Friends on the Road" blog, please be sure to keep this source http://supan.blog.51cto.com/7405859/1956899
IIS deployment flask implementation File Upload function