Example #1
0
# coding: utf-8
import os
from werkzeug import secure_filename
from flask import Flask, request, current_app, send_from_directory, render_template

from db import noticias_table

app = Flask("Flask-app")

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
app.config["MEDIA_ROOT"] = os.path.join(PROJECT_ROOT, "media_files")


@app.route("/")
def index():
    return render_template("home.html")


@app.route("/noticias/cadastro", methods=["GET", "POST"])
def cadastro():
    if request.method == "POST":

        dados_do_formulario = request.form.to_dict()
        imagem = request.files.get("imagem")

        if imagem:
            filename = secure_filename(imagem.filename)
            path = os.path.join(current_app.config["MEDIA_ROOT"], filename)
            imagem.save(path)
            dados_do_formulario["imagem"] = filename
Example #2
0
import admin
import model

app = Flask(__name__)
app.debug = True
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///blog.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
app.config["SECRET_KEY"] = "notasecret"
app.config["SECURITY_REGISTERABLE"] = True
app.config["SECURITY_PASSWORD_HASH"] = "bcrypt"
app.config["SECURITY_PASSWORD_SALT"] = "mysalt"  # "hash_123678*",
app.config["SECURITY_SEND_REGISTER_EMAIL"] = False

app.config["APP_ROOT"] = os.path.dirname(os.path.abspath(__file__))
app.config["APP_STATIC"] = os.path.join(app.config["APP_ROOT"], "static")
app.config["MEDIA_ROOT"] = os.path.join(app.config["APP_STATIC"], "media")
app.config["MEDIA_URL"] = "/static/media/"

try:
    os.makedirs(app.config["MEDIA_ROOT"])
except OSError:
    pass

with app.app_context():
    db.init_app(app)
    db.app = app

    shlf = Shelf(app)
    shlf.init_db(db)
    shlf.init_admin()
    shlf.init_security(User, Role)