Skip to content

Commit 4dda003

Browse files
committedJun 19, 2014
updated for pep8
1 parent 4e36c20 commit 4dda003

File tree

5 files changed

+80
-45
lines changed

5 files changed

+80
-45
lines changed
 

‎README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
Hello. Want to get started with Flask quickly? Good. You came to the right place. This Flask application framework is pre-configured with **Flask-SQLAlchemy**, **Flask-WTF**, **Fabric**, **Coverage**, and the **Bootstrap** frontend (among others). This will get your Flask app up and running on Heroku or PythonAnywhere quickly. Use this starter, boilerplate for all you new Flask projects. Cheers!
44

5+
![real-python-logo](https://raw.githubusercontent.com/realpython/about/master/rp_small.png)
6+
Designed for the [Real Python](http://www.realpython.com) course.
7+
58
Preview the skeleton app here - [http://www.flaskboilerplate.com/](http://www.flaskboilerplate.com/)
69

710
**EXAMPLE APP: [http://flasktaskr.herokuapp.com/](http://flasktaskr.herokuapp.com/)**
@@ -10,17 +13,15 @@ Preview the skeleton app here - [http://www.flaskboilerplate.com/](http://www.fl
1013

1114
Project Structure
1215
--------
13-
16+
1417
```sh
1518
├── Procfile
1619
├── Procfile.dev
1720
├── README.md
1821
├── app.py
1922
├── config.py
20-
├── config.pyc
2123
├── error.log
2224
├── forms.py
23-
├── forms.pyc
2425
├── models.py
2526
├── requirements.txt
2627
├── static
@@ -85,7 +86,7 @@ Project Structure
8586
$ git clone https://github.com/mjhea0/flask-boilerplate.git
8687
$ cd flask-boilerplate
8788
```
88-
89+
8990
2. Initialize and activate a virtualenv:
9091
```
9192
$ virtualenv --no-site-packages env
@@ -112,10 +113,10 @@ Deploying to Heroku
112113
2. Login to Heroku and download the [Heroku Toolbelt](https://toolbelt.heroku.com/)
113114
3. Once installed, open your command-line and run the following command - `heroku login`. Then follow the prompts:
114115

115-
```
116+
```
116117
Enter your Heroku credentials.
117118
Email: michael@mherman.org
118-
Password (typing will be hidden):
119+
Password (typing will be hidden):
119120
Could not find an existing public key.
120121
Would you like to generate one? [Yn]
121122
Generating new SSH public key.
@@ -129,7 +130,7 @@ Deploying to Heroku
129130
```
130131
web: python run.py
131132
```
132-
133+
133134
Then save the file in your applications root or main directory as *Procfile* (no extension). The word "web" indicates to Heroku that the application will be attached to the HTTP routing stack once deployed.
134135

135136
7. Create a local Git repository (if necessary):
@@ -145,21 +146,21 @@ Deploying to Heroku
145146
```
146147
$ heroku create <name_it_if_you_want>
147148
```
148-
149+
149150
9. Deploy your code to Heroku:
150151

151152
```
152153
$ git push heroku master
153154
```
154-
155+
155156
10. View the app in your browser:
156157

157158
```
158159
$ heroku open
159160
```
160161

161162
11. You app should look similar to this - [http://www.flaskboilerplate.com/](http://www.flaskboilerplate.com/)
162-
163+
163164
12. Having problems? Look at the Heroku error log:
164165

165166
```
@@ -168,26 +169,26 @@ Deploying to Heroku
168169

169170
### Deploying to PythonAnywhere
170171

171-
1. Install [Git](http://git-scm.com/downloads) and [Python](http://install.python-guide.org/) - if you don't already have them, of course.
172+
1. Install [Git](http://git-scm.com/downloads) and [Python](http://install.python-guide.org/) - if you don't already have them, of course.
172173

173-
> If you plan on working exclusively within PythonAnywhere, which you can, because it provides a cloud solution for hosting and developing your application, you can skip step one entirely. :)
174+
> If you plan on working exclusively within PythonAnywhere, which you can, because it provides a cloud solution for hosting and developing your application, you can skip step one entirely. :)
174175
175176
2. Sign up for [PythonAnywhere](https://www.pythonanywhere.com/pricing/), if you haven't already
176177
3. Once logged in, you should be on the Consoles tab.
177-
4. Clone this repo:
178+
4. Clone this repo:
178179
```
179180
$ git clone git://github.com/mjhea0/flask-boilerplate.git
180181
$ cd flask-boilerplate
181182
```
182-
183+
183184
5. Create and activate a virtualenv:
184185
```
185186
$ virtualenv venv --no-site-packages
186187
$ source venv/bin/activate
187188
```
188189

189190
6. Install requirements:
190-
```
191+
```
191192
$ pip install -r requirements.txt
192193
```
193194

@@ -207,7 +208,7 @@ Once the web app has been created (it'll take 20 seconds or so), you'll see a li
207208
from
208209

209210
```
210-
project_home = u'/home/your-username/mysite'
211+
project_home = u'/home/your-username/mysite'
211212
```
212213

213214
to
@@ -227,7 +228,7 @@ Once the web app has been created (it'll take 20 seconds or so), you'll see a li
227228
```
228229
from app import app as application
229230
```
230-
231+
231232
12. Save the file.
232233
13. Go to the website http://your-username.pythonanywhere.com/ (or your own domain if you specified a different one earlier), and you should see something like this - [http://www.flaskboilerplate.com/](http://www.flaskboilerplate.com/).
233234

@@ -237,8 +238,8 @@ Once the web app has been created (it'll take 20 seconds or so), you'll see a li
237238

238239
1. Start a bash console
239240
2. Run:
240-
241-
```
241+
242+
```
242243
$ ssh-keygen -t rsa
243244
```
244245

@@ -257,7 +258,7 @@ Once the web app has been created (it'll take 20 seconds or so), you'll see a li
257258

258259
PUSH and PULL away!
259260

260-
### What's next?
261+
### What's next?
261262

262263
1. Using Heroku? Make sure you deactivate your virtualenv once you're done deploying: `deactivate`
263264
2. Need to reactivate? (1) Unix - `source venv/bin/activate` (2) Windows - `venv\scripts\activate`
@@ -272,4 +273,4 @@ PUSH and PULL away!
272273
1. [Flask Documentation](http://flask.pocoo.org/docs/)
273274
2. [Flask Extensions](http://flask.pocoo.org/extensions/)
274275
1. [Real Python](http://www.realpythonfortheweb.com) :)
275-
276+

‎app.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#----------------------------------------------------------------------------#
2-
# Imports.
2+
# Imports
33
#----------------------------------------------------------------------------#
44

5-
from flask import * # do not use '*'; actually input the dependencies.
6-
from flask.ext.sqlalchemy import SQLAlchemy
5+
from flask import Flask
6+
# from flask.ext.sqlalchemy import SQLAlchemy
77
import logging
88
from logging import Formatter, FileHandler
99
from forms import *
@@ -39,44 +39,52 @@ def wrap(*args, **kwargs):
3939
# Controllers.
4040
#----------------------------------------------------------------------------#
4141

42+
4243
@app.route('/')
4344
def home():
4445
return render_template('pages/placeholder.home.html')
4546

47+
4648
@app.route('/about')
4749
def about():
4850
return render_template('pages/placeholder.about.html')
4951

52+
5053
@app.route('/login')
5154
def login():
5255
form = LoginForm(request.form)
53-
return render_template('forms/login.html', form = form)
56+
return render_template('forms/login.html', form=form)
57+
5458

5559
@app.route('/register')
5660
def register():
5761
form = RegisterForm(request.form)
58-
return render_template('forms/register.html', form = form)
62+
return render_template('forms/register.html', form=form)
63+
5964

6065
@app.route('/forgot')
6166
def forgot():
6267
form = ForgotForm(request.form)
63-
return render_template('forms/forgot.html', form = form)
68+
return render_template('forms/forgot.html', form=form)
6469

6570
# Error handlers.
6671

72+
6773
@app.errorhandler(500)
6874
def internal_error(error):
6975
#db_session.rollback()
7076
return render_template('errors/500.html'), 500
7177

78+
7279
@app.errorhandler(404)
73-
def internal_error(error):
80+
def not_found_error(error):
7481
return render_template('errors/404.html'), 404
7582

7683
if not app.debug:
7784
file_handler = FileHandler('error.log')
78-
file_handler.setFormatter(Formatter('%(asctime)s %(levelname)s: %(message)s '
79-
'[in %(pathname)s:%(lineno)d]'))
85+
file_handler.setFormatter(
86+
Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')
87+
)
8088
app.logger.setLevel(logging.INFO)
8189
file_handler.setLevel(logging.INFO)
8290
app.logger.addHandler(file_handler)

‎fabfile.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,48 @@
1-
from fabric.api import local, settings, abort, run
1+
from fabric.api import local, settings, abort
22
from fabric.contrib.console import confirm
33

44
# prepare for deployment
55

6+
67
def test():
78
with settings(warn_only=True):
8-
result = local("python test_tasks.py -v && python test_users.py -v", capture=True)
9+
result = local(
10+
"python test_tasks.py -v && python test_users.py -v", capture=True
11+
)
912
if result.failed and not confirm("Tests failed. Continue?"):
1013
abort("Aborted at user request.")
1114

15+
1216
def commit():
1317
message = raw_input("Enter a git commit message: ")
1418
local("git add . && git commit -am '{}'".format(message))
1519

20+
1621
def push():
1722
local("git push origin master")
1823

24+
1925
def prepare():
2026
test()
2127
commit()
2228
push()
2329

2430
# deploy to heroku
2531

32+
2633
def pull():
2734
local("git pull origin master")
2835

36+
2937
def heroku():
3038
local("git push heroku master")
3139

40+
3241
def heroku_test():
33-
local("heroku run python test_tasks.py -v && heroku run python test_users.py -v")
42+
local(
43+
"heroku run python test_tasks.py -v && heroku run python test_users.py -v"
44+
)
45+
3446

3547
def deploy():
3648
pull()
@@ -41,6 +53,6 @@ def deploy():
4153

4254
# rollback
4355

56+
4457
def rollback():
4558
local("heroku rollback")
46-

‎forms.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
from flask_wtf import Form
2-
from wtforms import TextField, DateField, IntegerField, \
3-
SelectField, PasswordField
2+
from wtforms import TextField, PasswordField
43
from wtforms.validators import DataRequired, EqualTo, Length
54

65
# Set your classes here.
76

7+
88
class RegisterForm(Form):
9-
name = TextField('Username', validators = [DataRequired(), Length(min=6, max=25)])
10-
email = TextField('Email', validators = [DataRequired(), Length(min=6, max=40)])
11-
password = PasswordField('Password', validators = [DataRequired(), Length(min=6, max=40)])
12-
confirm = PasswordField('Repeat Password', [DataRequired(), EqualTo('password', message='Passwords must match')])
9+
name = TextField(
10+
'Username', validators=[DataRequired(), Length(min=6, max=25)]
11+
)
12+
email = TextField(
13+
'Email', validators=[DataRequired(), Length(min=6, max=40)]
14+
)
15+
password = PasswordField(
16+
'Password', validators=[DataRequired(), Length(min=6, max=40)]
17+
)
18+
confirm = PasswordField(
19+
'Repeat Password',
20+
[DataRequired(),
21+
EqualTo('password', message='Passwords must match')]
22+
)
23+
1324

1425
class LoginForm(Form):
15-
name = TextField('Username', [DataRequired()])
16-
password = PasswordField('Password', [DataRequired()])
26+
name = TextField('Username', [DataRequired()])
27+
password = PasswordField('Password', [DataRequired()])
28+
1729

1830
class ForgotForm(Form):
19-
email = TextField('Email', validators = [DataRequired(), Length(min=6, max=40)])
31+
email = TextField(
32+
'Email', validators=[DataRequired(), Length(min=6, max=40)]
33+
)

‎models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from sqlalchemy import create_engine
22
from sqlalchemy.orm import scoped_session, sessionmaker
33
from sqlalchemy.ext.declarative import declarative_base
4-
from sqlalchemy import Column, Integer, String
5-
from app import db
4+
# from sqlalchemy import Column, Integer, String
5+
# from app import db
66

77
engine = create_engine('sqlite:///database.db', echo=True)
88
db_session = scoped_session(sessionmaker(autocommit=False,

0 commit comments

Comments
 (0)
Please sign in to comment.