-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
25 lines (20 loc) · 839 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from flask import Flask, render_template
from models import Cartoon, db
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///cartoons.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# связываем приложение и экземпляр SQLAlchemy
db.init_app(app)
@app.route('/')
def index():
cartoons = Cartoon.query.all()
return render_template('cartoons.html', cartoons=cartoons)
@app.route('/cartoon/<int:cartoon_id>')
def cartoon_detail(cartoon_id):
cartoon = Cartoon.query.get_or_404(cartoon_id)
# Извлекаем идентификатор видео из ссылки
video_url = cartoon.video
video_id = video_url.split('/')[-1]
return render_template('cartoon.html', cartoon=cartoon, video_id=video_id)
if __name__ == '__main__':
app.run(debug=True)