Skip to content

Commit 0579c4e

Browse files
committed
Refactor.
1 parent ab204ea commit 0579c4e

File tree

22 files changed

+540
-102
lines changed

22 files changed

+540
-102
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FLASK_ENV=production
2+
SECRET_KEY=YOURSECRETKEY
3+
SQLALCHEMY_DATABASE_URI=mysql+pymysql://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE_NAME]

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ verify_ssl = true
99
Flask = "*"
1010
Flask-SQLAlchemy = "*"
1111
PyMySQL = "*"
12-
python-dotenv = "*"
12+
Python-dotenv = "*"
1313

1414
[requires]
1515
python_version = "3.8"

Pipfile.lock

Lines changed: 39 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ $ pipenv update
3535
$ flask run
3636
```
3737

38-
## Configuration
38+
## Usage
3939

40-
Configuration is handled by creating a **.env** file. This should contain the following variables (replace the values with your own):
40+
Replace the values in **.env.example** with your values and rename this file to **.env**:
41+
42+
* `FLASK_APP`: Entry point of your application (should be `wsgi.py`).
43+
* `FLASK_ENV`: The environment to run your app in (either `development` or `production`).
44+
* `SECRET_KEY`: Randomly generated string of characters used to encrypt your app's data.
45+
* `SQLALCHEMY_DATABASE_URI`: SQLAlchemy connection URI to a SQL database.
46+
47+
*Remember never to commit secrets saved in .env files to Github.*
4148

42-
```.env
43-
FLASK_ENV="production"
44-
SECRET_KEY="YOURSECRETKEY"
45-
SQLALCHEMY_DATABASE_URI="mysql+pymysql://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE_NAME]"
46-
```
4749
-----
4850

4951
**Hackers and Slackers** tutorials are free of charge. If you found this tutorial helpful, a [small donation](https://www.buymeacoffee.com/hackersslackers) would be greatly appreciated to keep us in business. All proceeds go towards coffee, and all coffee goes towards more content.

application/models.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

application/routes.py

Lines changed: 0 additions & 25 deletions
This file was deleted.
-564 KB
Binary file not shown.

config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Flask configuration variables."""
12
from os import environ, path
23
from dotenv import load_dotenv
34

@@ -6,13 +7,12 @@
67

78

89
class Config:
9-
"""Set Flask configuration variables from .env file."""
10+
"""Set Flask configuration from .env file."""
1011

11-
# General Flask Config
12+
# General Config
1213
SECRET_KEY = environ.get('SECRET_KEY')
14+
FLASK_APP = environ.get('FLASK_APP')
1315
FLASK_ENV = environ.get('FLASK_ENV')
14-
FLASK_APP = 'wsgi.py'
15-
FLASK_DEBUG = 1
1616

1717
# Database
1818
SQLALCHEMY_DATABASE_URI = environ.get("SQLALCHEMY_DATABASE_URI")

application/__init__.py renamed to flask_sqlalchemy_tutorial/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Initialize Flask app."""
12
from flask import Flask
23
from flask_sqlalchemy import SQLAlchemy
34

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Data models."""
2+
from . import db
3+
4+
5+
class User(db.Model):
6+
"""Data model for user accounts."""
7+
8+
__tablename__ = 'flasksqlalchemy-tutorial-users'
9+
id = db.Column(
10+
db.Integer,
11+
primary_key=True
12+
)
13+
username = db.Column(
14+
db.String(64),
15+
index=False,
16+
unique=True,
17+
nullable=False
18+
)
19+
email = db.Column(
20+
db.String(80),
21+
index=True,
22+
unique=True,
23+
nullable=False
24+
)
25+
created = db.Column(
26+
db.DateTime,
27+
index=False,
28+
unique=False,
29+
nullable=False
30+
)
31+
bio = db.Column(
32+
db.Text,
33+
index=False,
34+
unique=False,
35+
nullable=True
36+
)
37+
admin = db.Column(
38+
db.Boolean,
39+
index=False,
40+
unique=False,
41+
nullable=False
42+
)
43+
44+
def __repr__(self):
45+
return '<User {}>'.format(self.username)

0 commit comments

Comments
 (0)