Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, redirect, url_for
|
| 2 |
+
import os
|
| 3 |
+
from werkzeug.utils import secure_filename
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
app.config['UPLOAD_FOLDER'] = 'static/stories'
|
| 7 |
+
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
| 8 |
+
|
| 9 |
+
stories = []
|
| 10 |
+
|
| 11 |
+
@app.route('/')
|
| 12 |
+
def index():
|
| 13 |
+
return render_template('index.html', stories=stories)
|
| 14 |
+
|
| 15 |
+
@app.route('/add_story', methods=['POST'])
|
| 16 |
+
def add_story():
|
| 17 |
+
if 'photo' in request.files:
|
| 18 |
+
photo = request.files['photo']
|
| 19 |
+
if photo.filename != '':
|
| 20 |
+
filename = secure_filename(photo.filename)
|
| 21 |
+
photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
| 22 |
+
stories.insert(0, {'image': url_for('static', filename=f'stories/{filename}')})
|
| 23 |
+
return redirect(url_for('index'))
|
| 24 |
+
|
| 25 |
+
if __name__ == '__main__':
|
| 26 |
+
app.run(debug=True, port=7860)
|