Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, request, render_template, url_for
- import os
- app = Flask(__name__)
- UPLOAD_DIR = '/var/www/uploads/'
- ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
- # utility methods
- def allowed_file(filename):
- return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
- @app.route('/')
- def root():
- return render_template('index.html')
- @app.route('/login', methods=['GET', 'POST'])
- def login():
- if request.method == 'POST':
- username = request.form['username']
- password = request.form['password']
- return render_template('welcome.html', username=username, password=password)
- else:
- return render_template('login.html')
- @app.route('/info')
- def info():
- return "Nimbus file sharing app is running on Flask, SQLAlchemy, Apache stack"
- @app.route('/upload', methods=['GET', 'POST'])
- def upload():
- if request.method == 'POST':
- uploaded_file = request.files['uploaded_file']
- file_name = uploaded_file.filename
- if uploaded_file and allowed_file(file_name):
- uploaded_file.save(os.path.join(UPLOAD_DIR, file_name))
- download_url = "/download/" + file_name
- return render_template('download.html', download_url=download_url)
- else:
- return render_template('upload.html', message="No file to upload")
- else:
- return render_template('upload.html')
- @app.route('/download/<filename>')
- def download_file(filename):
- return "You are downloading File: " + filename
- if __name__ == '__main__':
- app.secret_key = 'J\\6\x1f8=\x1c\x90\x1b\x1c\xe1\xa4\x0fd\xd2\xee\xcb\xbf\xda\xed\x91\n\x96E'
- app.debug = True
- app.run()
Add Comment
Please, Sign In to add comment