Skip to content

Instantly share code, notes, and snippets.

@vikasavnish
Created June 29, 2018 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikasavnish/94fe80bce5c0910a68f597db2dc3d412 to your computer and use it in GitHub Desktop.
Save vikasavnish/94fe80bce5c0910a68f597db2dc3d412 to your computer and use it in GitHub Desktop.
flask_file_upload
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