Skip to content

Commit 4fb2eb9

Browse files
committed
✨ (Flask-JWT-Extended) Add section with start/end folders and no content yet
1 parent 57fbcb7 commit 4fb2eb9

File tree

419 files changed

+17360
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

419 files changed

+17360
-3
lines changed

docs/docs-upcoming/08_flask_jwt_extended/01_project_overview/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/docs-upcoming/08_flask_jwt_extended/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Changes in this section
3+
description: Overview of the API endpoints we'll use for user registration and authentication.
4+
---
5+
6+
# Changes in this section
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: What is a JWT?
3+
description: Understand what a JWT is, what data it contains, and how it may be used.
4+
---
5+
6+
# What is a JWT?
7+
8+
- What is stored in a JWT?
9+
- When does a JWT expire?
10+
- What happens when the JWT expires?
11+
- How does a client use a JWT?
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Flask-JWT-Extended setup
3+
description: Install and set up the Flask-JWT-Extended extension with our REST API.
4+
---
5+
6+
# Many-to-many relationships
7+
8+
- [x] Set metadata above
9+
- [ ] Start writing!
10+
- [x] Create `start` folder
11+
- [x] Create `end` folder
12+
- [ ] Create per-file diff between `end` and `start` (use "Compare Folders")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.venv
2+
*.pyc
3+
__pycache__
4+
data.db
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
per-file-ignores = __init__.py:F401
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FLASK_APP=app
2+
FLASK_ENV=development
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM python:3.10
2+
WORKDIR /app
3+
COPY ./requirements.txt requirements.txt
4+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
5+
COPY . .
6+
CMD ["gunicorn", "--bind", "0.0.0.0:80", "app:create_app()"]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from flask import Flask
2+
from flask_smorest import Api
3+
from flask_jwt_extended import JWTManager
4+
5+
from db import db
6+
7+
from resources.item import blp as ItemBlueprint
8+
from resources.store import blp as StoreBlueprint
9+
from resources.tag import blp as TagBlueprint
10+
11+
12+
def create_app(db_url=None):
13+
app = Flask(__name__)
14+
app.config["API_TITLE"] = "Stores REST API"
15+
app.config["API_VERSION"] = "v1"
16+
app.config["OPENAPI_VERSION"] = "3.0.3"
17+
app.config["OPENAPI_URL_PREFIX"] = "/"
18+
app.config["OPENAPI_SWAGGER_UI_PATH"] = "/swagger-ui"
19+
app.config[
20+
"OPENAPI_SWAGGER_UI_URL"
21+
] = "https://cdn.jsdelivr.net/npm/swagger-ui-dist/"
22+
app.config["SQLALCHEMY_DATABASE_URI"] = db_url or "sqlite:///data.db"
23+
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
24+
app.config["PROPAGATE_EXCEPTIONS"] = True
25+
db.init_app(app)
26+
api = Api(app)
27+
28+
"""
29+
JWT related configuration. The following functions includes:
30+
1) add claims to each jwt
31+
2) customize the token expired error message
32+
"""
33+
app.config["JWT_SECRET_KEY"] = "jose"
34+
jwt = JWTManager(app)
35+
36+
@app.before_first_request
37+
def create_tables():
38+
import models # noqa: F401
39+
40+
db.create_all()
41+
42+
api.register_blueprint(ItemBlueprint)
43+
api.register_blueprint(StoreBlueprint)
44+
api.register_blueprint(TagBlueprint)
45+
46+
return app

0 commit comments

Comments
 (0)