blog.py — flask Source File
Architecture documentation for blog.py, a python file in the flask codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR bf08e60d_e030_cf15_e246_1de85afd9b5e["blog.py"] 749d9792_d880_75ed_5ccb_68e2218e2db3["auth.py"] bf08e60d_e030_cf15_e246_1de85afd9b5e --> 749d9792_d880_75ed_5ccb_68e2218e2db3 e8823169_a1d2_bbd1_d687_0272900d9222["login_required"] bf08e60d_e030_cf15_e246_1de85afd9b5e --> e8823169_a1d2_bbd1_d687_0272900d9222 09048b06_50a3_09e1_0ff4_ee97994a3e9b["db.py"] bf08e60d_e030_cf15_e246_1de85afd9b5e --> 09048b06_50a3_09e1_0ff4_ee97994a3e9b adc04a87_eacf_cc39_8808_98d7d38c7044["get_db"] bf08e60d_e030_cf15_e246_1de85afd9b5e --> adc04a87_eacf_cc39_8808_98d7d38c7044 8c762fc5_c0b6_0d4d_3889_896d80fbf225["flask"] bf08e60d_e030_cf15_e246_1de85afd9b5e --> 8c762fc5_c0b6_0d4d_3889_896d80fbf225 9b468bc7_cc0b_fef2_ed71_07b4f027fb55["werkzeug.exceptions"] bf08e60d_e030_cf15_e246_1de85afd9b5e --> 9b468bc7_cc0b_fef2_ed71_07b4f027fb55 style bf08e60d_e030_cf15_e246_1de85afd9b5e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from flask import Blueprint
from flask import flash
from flask import g
from flask import redirect
from flask import render_template
from flask import request
from flask import url_for
from werkzeug.exceptions import abort
from .auth import login_required
from .db import get_db
bp = Blueprint("blog", __name__)
@bp.route("/")
def index():
"""Show all the posts, most recent first."""
db = get_db()
posts = db.execute(
"SELECT p.id, title, body, created, author_id, username"
" FROM post p JOIN user u ON p.author_id = u.id"
" ORDER BY created DESC"
).fetchall()
return render_template("blog/index.html", posts=posts)
def get_post(id, check_author=True):
"""Get a post and its author by id.
Checks that the id exists and optionally that the current user is
the author.
:param id: id of post to get
:param check_author: require the current user to be the author
:return: the post with author information
:raise 404: if a post with the given id doesn't exist
:raise 403: if the current user isn't the author
"""
post = (
get_db()
.execute(
"SELECT p.id, title, body, created, author_id, username"
" FROM post p JOIN user u ON p.author_id = u.id"
" WHERE p.id = ?",
(id,),
)
.fetchone()
)
if post is None:
abort(404, f"Post id {id} doesn't exist.")
if check_author and post["author_id"] != g.user["id"]:
abort(403)
return post
@bp.route("/create", methods=("GET", "POST"))
// ... (66 more lines)
Domain
Subdomains
Dependencies
- auth.py
- db.py
- flask
- get_db
- login_required
- werkzeug.exceptions
Source
Frequently Asked Questions
What does blog.py do?
blog.py is a source file in the flask codebase, written in python. It belongs to the ApplicationCore domain, ExtensionRegistry subdomain.
What functions are defined in blog.py?
blog.py defines 5 function(s): create, delete, get_post, index, update.
What does blog.py depend on?
blog.py imports 6 module(s): auth.py, db.py, flask, get_db, login_required, werkzeug.exceptions.
Where is blog.py in the architecture?
blog.py is located at examples/tutorial/flaskr/blog.py (domain: ApplicationCore, subdomain: ExtensionRegistry, directory: examples/tutorial/flaskr).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free