示例#1
0
def add_dish():
    if 'username' not in session:
        return redirect('/login')
    form = AddDishForm()
    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        dish = DishModel(db.get_connection())
        dish.insert(title,content,session['user_id'])
        return redirect("/index")
    return render_template('add_dish.html', title='Рецепты',
                           form=form, username=session['username'])
示例#2
0
def index():
    if 'username' not in session:
        return render_template('homepage.html')
    dish = DishModel(db.get_connection()).get_all()
    return render_template('index.html',
                           username=session['username'],
                           dish=dish)
示例#3
0
def delete_dish(dish_id):
    if 'username' not in session:
        return redirect('/login')
    nm = DishModel(db.get_connection())
    nm.delete(dish_id)
    return redirect("/index")
示例#4
0
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import DataRequired

from registerform import RegisterForm
from loginform import LoginForm
from add_dish import AddDishForm
from dishmodel import DishModel
from usersmodel import UsersModel
from db import DB

app = Flask(__name__)
app.config['SECRET_KEY'] = 'yandexlyceum_secret_key'

db = DB()
UsersModel(db.get_connection()).init_table()
DishModel(db.get_connection()).init_table()

@app.route('/')
@app.route('/index')
def index():
    if 'username' not in session:
        return render_template('homepage.html')  
    dish = DishModel(db.get_connection()).get_all()
    return render_template('index.html', username=session['username'], dish = dish)

@app.route('/homepage')
def homepage():
    return render_template('homepage.html')

@app.route('/login', methods=['GET', 'POST'])
def login():