File tree 7 files changed +90
-0
lines changed
7 files changed +90
-0
lines changed Original file line number Diff line number Diff line change
1
+ __pycache__ /
2
+ * .db
Original file line number Diff line number Diff line change
1
+ web : python main.py
Original file line number Diff line number Diff line change
1
+ # Flask Calculator
2
+
3
+ ## To Run
4
+
5
+ All commands to be run from inside the repository directory.
6
+ ```
7
+ $ pip install -r requirements.txt
8
+ $ python setup.py
9
+ $ python main.py
10
+ ```
11
+
12
+ ## To Publish to Heroku
13
+
14
+ All commands to be run from inside the repository directory.
15
+ ```
16
+ $ git init # Only necessary if this is not already a git repository
17
+ $ heroku create
18
+ $ git push heroku master # If you have any changes or files to add, commit them before you push.
19
+ $ heroku addons:create heroku-postgresql:hobby-dev
20
+ $ heroku run python setup.py
21
+ $ heroku open
22
+ ```
Original file line number Diff line number Diff line change
1
+ import os
2
+ import base64
3
+
4
+ from flask import Flask , request
5
+ from model import Message
6
+
7
+ app = Flask (__name__ )
8
+
9
+ @app .route ('/' , methods = ['GET' , 'POST' ])
10
+ def home ():
11
+
12
+ if request .method == 'POST' :
13
+ m = Message (content = request .form ['content' ])
14
+ m .save ()
15
+
16
+ body = """
17
+ <html>
18
+ <body>
19
+ <h1>Class Message Board</h1>
20
+ <h2>Contribute to the Knowledge of Others</h2>
21
+ <form method="POST">
22
+ <textarea name="content"></textarea>
23
+ <input type="submit" value="Submit">
24
+ </form>
25
+
26
+ <h2>Wisdom From Your Fellow Classmates</h2>
27
+ """
28
+
29
+ for m in Message .select ():
30
+ body += """
31
+ <div class="message">
32
+ {}
33
+ </div>
34
+ """ .format (m .content )
35
+
36
+ return body
37
+
38
+
39
+ if __name__ == "__main__" :
40
+ port = int (os .environ .get ("PORT" , 6738 ))
41
+ app .run (host = '0.0.0.0' , port = port )
42
+
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ from peewee import Model , CharField , IntegerField
4
+ from playhouse .db_url import connect
5
+
6
+ db = connect (os .environ .get ('DATABASE_URL' , 'sqlite:///my_database.db' ))
7
+
8
+ class Message (Model ):
9
+ content = CharField (max_length = 1024 , unique = True )
10
+
11
+ class Meta :
12
+ database = db
Original file line number Diff line number Diff line change
1
+ click == 6.7
2
+ Flask == 1.0.2
3
+ itsdangerous == 0.24
4
+ Jinja2 == 2.10
5
+ MarkupSafe == 1.0
6
+ peewee == 3.3.4
7
+ Werkzeug == 0.14.1
Original file line number Diff line number Diff line change
1
+ from model import db , Message
2
+
3
+ db .connect ()
4
+ db .create_tables ([Message ])
You can’t perform that action at this time.
0 commit comments