Skip to content

Commit 2e351a0

Browse files
committed
Updated README, added pyproject.toml.
1 parent 4320632 commit 2e351a0

File tree

7 files changed

+63
-15
lines changed

7 files changed

+63
-15
lines changed

Pipfile.lock

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

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Flask-SQLAlchemy Tutorial
22

33
![Python](https://img.shields.io/badge/Python-v^3.8-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
4-
![Flask](https://img.shields.io/badge/Flask-v1.1.1-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
4+
![Flask](https://img.shields.io/badge/Flask-v1.1.2-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
55
![Flask-SQLAlchemy](https://img.shields.io/badge/Flask--SQLAlchemy-2.4.1-red.svg?longCache=true&style=flat-square&logo=flask&logoColor=white&colorA=4c566a&colorB=5e81ac)
66
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c)
77
[![GitHub Issues](https://img.shields.io/github/issues/hackersandslackers/flask-sqlalchemy-tutorial.svg?style=flat-square&colorA=4c566a&colorB=ebcb8b&logo=Github)](https://github.com/hackersandslackers/flask-sqlalchemy-tutorial/issues)
@@ -12,26 +12,38 @@
1212

1313
Connect your Flask app to a database using Flask-SQLAlchemy. This repository contains source code for the accompanying tutorial on [Hackers and Slackers](https://hackersandslackers.com/manage-database-models-with-flask-sqlalchemy/).
1414

15-
## Getting Started
15+
## Installation
1616

17-
Installation is recommended with Pipenv:
17+
**Installation via `requirements.txt`**:
1818

1919
```shell
2020
$ git clone https://github.com/hackersandslackers/flask-sqlalchemy-tutorial.git
2121
$ cd flask-sqlalchemy-tutorial
22-
$ pipenv shell
23-
$ pipenv update
22+
$ python3 -m venv myenv
23+
$ source myenv/bin/activate
24+
$ pip3 install -r requirements.txt
2425
$ flask run
2526
```
2627

27-
Alternatively, try installing via `requirements.txt`:
28+
**Installation via [Pipenv](https://pipenv-fork.readthedocs.io/en/latest/)**:
2829

2930
```shell
3031
$ git clone https://github.com/hackersandslackers/flask-sqlalchemy-tutorial.git
31-
$ cd flasksession-tutorial
32-
$ python3 -m pip install requirements.txt
32+
$ cd flask-sqlalchemy-tutorial
33+
$ pipenv shell
34+
$ pipenv update
3335
$ flask run
3436
```
37+
38+
## Configuration
39+
40+
Configuration is handled by creating a **.env** file. This should contain the following variables (replace the values with your own):
41+
42+
```.env
43+
FLASK_ENV="production"
44+
SECRET_KEY="YOURSECRETKEY"
45+
SQLALCHEMY_DATABASE_URI="mysql+pymysql://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE_NAME]"
46+
```
3547
-----
3648

3749
**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/routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
@app.route('/', methods=['GET'])
88
def create_user():
9-
"""Create a user."""
9+
"""Create a user via query string parameters."""
1010
username = request.args.get('user')
1111
email = request.args.get('email')
1212
if username and email:
@@ -20,6 +20,6 @@ def create_user():
2020
admin=False) # Create an instance of the User class
2121
db.session.add(new_user) # Adds new User record to database
2222
db.session.commit() # Commits all changes
23-
return render_template('users.html',
23+
return render_template('users.jinja2',
2424
users=User.query.all(),
2525
title="Show Users")
File renamed without changes.

application/templates/users.html renamed to application/templates/users.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% extends "layout.html" %}
1+
{% extends "layout.jinja2" %}
22

33
{% block content %}
44
<div class="container">

pyproject.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[tool.poetry]
2+
name = "Flask SQLAlchemy Tutorial"
3+
version = "0.1.0"
4+
description = "Connect your Flask app to a database using Flask-SQLAlchemy."
5+
authors = ["Todd Birchard <toddbirchard@gmail.com>"]
6+
maintainers = ["Todd Birchard <toddbirchard@gmail.com>"]
7+
license = "MIT"
8+
readme = "README.md"
9+
homepage = "https://hackersandslackers.com/flask-sqlalchemy-database-models/"
10+
repository = "https://github.com/hackersandslackers/flask-sqlalchemy-tutorial/"
11+
documentation = "https://hackersandslackers.com/flask-sqlalchemy-database-models/"
12+
keywords = ["Flask",
13+
"SQLAlchemy",
14+
"SQL",
15+
"Frameworks",
16+
"Tutorial"]
17+
18+
[tool.poetry.dependencies]
19+
python = "^3.8"
20+
flask = "*"
21+
flask-sqlalchemy = "*"
22+
pymysql = "*"
23+
python-dotenv = "*"
24+
25+
[tool.poetry.dev-dependencies]
26+
pytest = "*"
27+
28+
[build-system]
29+
requires = ["poetry>=0.12"]
30+
build-backend = "poetry.masonry.api"
31+
32+
[tool.poetry.scripts]
33+
run = "wsgi:__main__"
34+
35+
[tool.poetry.urls]
36+
issues = "https://github.com/hackersandslackers/flask-sqlalchemy-tutorial/issues"

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
click==7.1.1
1+
click==7.1.2
22
Flask==1.1.2
33
Flask-SQLAlchemy==2.4.1
44
itsdangerous==1.1.0

0 commit comments

Comments
 (0)