Python Upload and Download file using Flask Web development Not Working
Shalini Ravishankar
shalini.ravishankar at gmail.com
Tue Mar 10 01:04:06 EDT 2015
Hello Everyone,
I am new to Python Web development. I am creating a Web Page with FLask. The Pages takes input as file (file upload) and the process the file and gives the output as a file(downloading the file)
But I am having error.
My Python file :
from flask import Flask
from flask import render_template
from flask import request, send_from_directory
from werkzeug import secure_filename
import os
import commandFile
app = Flask(__name__)
UPLOAD_FOLDER = 'F:/uploads/'
ALLOWED_EXTENSIONS = set(['txt'])
@app.route('/')
@app.route('/home')
def home_page():
return render_template('home.html')
@app.route('/process', methods=['GET', 'POST'])
def process_page():
if request.method == 'POST':
tool_selected = request.form['tool_list']
print tool_selected
# Get the name of the uploaded file
file = request.files['fileToupload']
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
input_file = UPLOAD_FOLDER + filename
print input_file
return render_template('process.html', input_file = input_file, tool_selected =tool_selected )
The Form in home.html :
<form action="process" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-md-4">
<p>
Input File
</p></div>
<div class="col-md-8"><input name ='fileToupload' type="file" style="font-family: Baskerville, 'Palatino Linotype', Palatino, 'Century Schoolbook L', 'Times New Roman', serif;
font-size:20pt; font-style:bold" required>
</div>
</div>
</form>
Action process.html :
<div class="container">
<div class="box">
<p id = "part1">You File has been Uploaded.
Please wait ... Your file is being processed. </p>
<% import commandFile
processing = commandFile.Command_Process(tool_selected, input_file) %>
processing.processFile() %>
<script>
document.getElementById("part1").innerHTML = "You File is Processed. Download will begin Automatically";
</script>
</div>
</div>
But the output is
You File is Processed. Download will begin Automatically
<% import commandFile processing = commandFile.Command_Process(tool_selected, input_file) %> processing.processFile() %>
The python script is not executing, it is displaying in html.
Can some one tell me how do I do thid.
More information about the Python-list
mailing list