Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

IIS deploys flask to implement file upload function

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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 in the configuration commit path "MACHINE/WEBROOT/APPHOST" to the "system.webServer/fastCgi" section of "MACHINE/WEBROOT/APPHOST"

"d:\ software\ python27\ python.exe | d:\ software\ python27\ lib\ site-packages\ wfastcgi.pyc" can now be used as a FastCGI script processor

3. Install flask

Pip install flask

4. Turn on the windows function, install IIS, enable CGI5, install URL rewriting

IIS requires that the URL rewrite component be installed, which can be installed through Microsoft Web Platform Installer. Run after downloading Microsoft Web Platform Installer, search for URL, and install the URL rewriting tool.

6. Configure IIS6.1 to add a website, and the root directory is d:\ data\ mysite\ upload

6.2d:\ data\ mysite\ upload directory structure

Upload

-static file directory of the static upload directory

-upload.py upload file program

-web.config profile

6.3 web.config content in the upload directory

Note:

The content of scriptProcessor is to execute the output of wfastcgi-enable

Value of WSGI_HANDLER

Value of PYTHONPATH

The directory of WSGI_LOG must exist

6.4 Code for uploading files by upload.py # _ * _ 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' 'Upload new File Upload new File

'' @ app.route ('/ upload/') def uploaded_file (filename): return u' file uploaded successfully'if _ _ name__ ='_ _ main__': app.run () 7, flask learning website

Http://docs.jinkan.org/docs/flask/

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report