from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///books.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class horror(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(50))
author = db.Column(db.String(50))
content = db.Column(db.Text)
price = db.Column(db.Integer)
date_posted = db.Column(db.DateTime)
class teen(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(50))
author = db.Column(db.String(50))
content = db.Column(db.Text)
price = db.Column(db.Integer)
date_posted = db.Column(db.DateTime)
class adult(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(50))
author = db.Column(db.String(50))
content = db.Column(db.Text)
price = db.Column(db.Integer)
date_posted = db.Column(db.DateTime)
class fantasy(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(50))
author = db.Column(db.String(50))
content = db.Column(db.Text)
price = db.Column(db.Integer)
date_posted = db.Column(db.DateTime)
class bought(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50))
email = db.Column(db.String(50))
phone = db.Column(db.String)
city = db.Column(db.String)
newpost = db.Column(db.String)
promo = db.Column(db.String)
@app.route('/')
def index():
return render_template('Главная.html')
@app.route('/')
def about():
return render_template('Страница-1.html')
@app.route('/admin')
def addbook():
return render_template('О-нас.html')
@app.route('/addpost', methods=['POST', 'GET'])
def addpost():
genre = request.form['genre']
title = request.form['title']
price = request.form['price']
author = request.form['author']
content = request.form['content']
if genre == 'horror':
horror = horror(title=title, price=price, author=author, content=content)
db.session.add(horror)
db.session.commit()
return redirect(url_for('Главная'))
elif genre == 'fantasy':
fantasy=fantasy(title=title, price=price, author=author, content=content)
db.session.add(fantasy)
db.session.commit()
elif genre == 'adult':
adult=adult(title=title, price=price, author=author, content=content)
db.session.add(adult)
db.session.commit()
elif genre == 'teen':
teen=teen(title=title, price=price, author=author, content=content)
db.session.add(teen)
db.session.commit()
@app.route('/')
def BYE():
return render_template('Контакты.html')
if __name__ == '__main__':
app.run(debug=True)
Ничего не могу понять. Должно работать, но не хочет. Подскажите что исправить. Спасибо,