Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- basedir = os.path.abspath(os.path.dirname(__file__))
- UPLOAD_FOLDER = '/static/images'
- ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
- app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
- @app.route('/', methods=['GET', 'POST'])
- @login_required
- def index():
- if request.method == "POST":
- # storing pictures
- files = request.files.getlist("img")
- if not files:
- return apology("No files")
- # if user does not select file, browser also
- # submit an empty part without filename
- for file in files:
- if allowed_file(file.filename):
- filename = secure_filename(file.filename)
- img_path=file.save(os.path.join(basedir, app.config['UPLOAD_FOLDER'], filename))
- # insert into the database
- db.execute("INSERT INTO images (id, img_path) VALUES (:id, :img_path)", id=session["user_id"],
- img_path=img_path)
- else:
- return apology("Give me some images!")
- # storing text storing text
- text = request.form.get("Inspirational text")
- if text:
- if len(text) > 15:
- return apology("Message has to be less then 15 characters.")
- #db.execute("INSERT INTO users (id, text) VALUES(:id, :text)", id=session["user_id"], text = text)
- else:
- return apology("Say something inspiring!")
- db.execute("UPDATE users SET text = :text WHERE id = :id", id=session["user_id"], text = text)
- user_images = db.execute("SELECT img_path FROM images WHERE id = :id", id=session["user_id"])
- user_texts = db.execute("SELECT text FROM users WHERE id = :id", id =session["user_id"])
- return render_template("show.html", user_images = user_images, user_texts = user_texts)
- else:
- return render_template('index.html')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement