Created
June 29, 2018 11:36
-
-
Save vikasavnish/94fe80bce5c0910a68f597db2dc3d412 to your computer and use it in GitHub Desktop.
flask_file_upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask,render_template,jsonify,Response,json,url_for,request | |
import os | |
app = Flask(__name__) | |
UPLOAD_FOLDER=os.path.basename("uploads") | |
ALLOWED_EXTENSIONS = set(['csv']) | |
app.config['UPLOAD_FOLDER']=UPLOAD_FOLDER | |
def allowed_file(filename): | |
return '.' in filename and \ | |
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS | |
@app.route('/') | |
def hello_world(): | |
return render_template("home.html") | |
@app.route('/keywords') | |
def keywords(): | |
data= jsonify( | |
username="vikas", | |
email="vikas", | |
id=12 | |
) | |
return data | |
@app.route('/upload',methods=['GET','POST']) | |
def upload(): | |
if request.method=="POST": | |
file= request.files.get('csvupload') | |
f = os.path.join(app.config['UPLOAD_FOLDER'], file.filename) | |
file.save(f) | |
print (file) | |
return render_template("files.html") | |
else: | |
return render_template("files.html") | |
@app.route('/about') | |
def about(): | |
return 'my website quick easy and simple' | |
if __name__=="__main__": | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment