-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
142 lines (105 loc) · 3.67 KB
/
run.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from flask import Flask, request, render_template
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app = Flask(__name__)
app.config.update(
SECRET_KEY='topsecret',
SQLALCHEMY_DATABASE_URI='postgresql://postgres:password@localhost/catalog_db',
SQLALCHEMY_TRACK_MODIFICATIONS=False
)
db = SQLAlchemy(app)
@app.route("/index")
@app.route("/")
def hello_flask():
return 'Hello flask.!!'
@app.route("/new")
def query_strings(greeting = 'hello'):
query_val = request.args.get('greeting', greeting)
return '<h1> the greeting is : {0} </h1>'.format(query_val)
@app.route("/user")
@app.route("/user/<name>")
def no_query_string(name="apoo"):
return '<h1> hello there.! {} </h1>'.format(name)
@app.route("/text/<string:name>")
def working_with_strings(name):
return '<h1> here is a string: ' + name + ' </h1>'
@app.route("/numbers/<int:num>")
def working_with_numbers(num):
return '<h1> here is a number: ' + str(num) + ' </h1>'
@app.route("/add/<int:num1>/<int:num2>")
def adding_integers(num1, num2):
return '<h1> the sum is: {}'.format(num1+num2) + ' </h1>'
@app.route('/product/<float:num1>/<float:num2>')
def product_two_numbers(num1, num2):
return '<h1> the product is: {}'.format(num1 * num2) + '</h1>'
@app.route("/tmp")
def using_template():
return render_template('hello.html')
@app.route('/watch')
def top_movies():
movie_list = [
'autospy of jane doe',
'neon demon',
'kong: skull island',
'john wick 2',
'spiderman - homecoming'
]
return render_template('movies.html', movies=movie_list, name='Harry' )
@app.route('/filters')
def filter_data():
movie_dict = {
'autospy of jane doe': 02.14,
'neon demon': 3.20,
'kong: skull island': 1.50,
'john wick 2': 2.52,
'spiderman - homecoming': 1.48,
'a christmas carol': 2.5
}
return render_template('filter_data.html',
movies=movie_dict,
name=None,
film='a christmas carol')
@app.route('/macros')
def jinja_macros():
movie_dict = {
'autospy of jane doe': 02.14,
'neon demon': 3.20,
'kong: skull island': 1.50,
'john wick 2': 2.52,
'spiderman - homecoming': 1.48,
'a christmas carol': 2.5
}
return render_template('using_macros.html', movies=movie_dict)
class Publication(db.Model):
__tablename__ = 'publication'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)
def __init__(self, name):
#self.id = id
self.name = name
def __repr__(self):
return 'The id is {}, Name is {}'.format(self.id, self.name)
class Book(db.Model):
__tablename__ = 'book'
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(500), nullable=False, index=True)
author = db.Column(db.String(350))
avg_rating = db.Column(db.Float)
format = db.Column(db.String(50))
image = db.Column(db.String(100), unique=True)
num_pages = db.Column(db.Integer)
pub_date = db.Column(db.DateTime, default=datetime.utcnow())
pub_id = db.Column(db.Integer, db.ForeignKey('publication.id'))
def __init__(self, title, author, avg_rating, book_format, image, num_pages, pub_id):
self.title = title
self.author = author
self.avg_rating = avg_rating
self.format = book_format
self.image = image
self.num_pages = num_pages
self.pub_id = pub_id
def __repr__(self):
return '{} by {}'.format(self.title, self.author)
if __name__ == '__main__':
db.create_all()
app.run(debug=True)