Skip to content

Commit

Permalink
feat: add other base flask files
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkflame72 committed Mar 29, 2024
1 parent f92dc10 commit 019707d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/content/docs/guides/python/flask/authentication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Authentication
description: A simple website built using flask
sidebar:
order: 10
---
6 changes: 6 additions & 0 deletions src/content/docs/guides/python/flask/form-validation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Proper Form Handling
description: A simple website built using flask
sidebar:
order: 11
---
6 changes: 6 additions & 0 deletions src/content/docs/guides/python/flask/sqlalchemy.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Handling Databases with SQLAlchemy
description: A simple website built using flask
sidebar:
order: 12
---
14 changes: 12 additions & 2 deletions src/content/docs/guides/python/flask/templates.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ sidebar:

Writing HTML in Python code is not a good practice. It is hard to maintain, understand and becomes really difficult with larger pages. Flask provides a way to write HTML in separate files and then use them in the Python code. These files are called [templates](https://flask.palletsprojects.com/en/3.0.x/templating/) which are built using [Jinja2](https://jinja.palletsprojects.com/en/3.0.x/).

## What are Templates
## Jinja2 Templates

Templates are special HTML files that contain placeholders for dynamic content. These placeholders are replaced with actual values when the template is rendered. Templates are used to separate the presentation logic from the business logic.

Flask stores all of its templates in a folder called `templates`. This folder should be created in the same directory as the `app.py` file.

import { FileTree } from '@astrojs/starlight/components';

<FileTree>

- app.py
- templates/
- index.html

</FileTree>

### Creating a Template

```html
Expand All @@ -34,7 +44,7 @@ import { Steps } from '@astrojs/starlight/components';

<Steps>

1. The overall file is HTML so requires all the base HTML tags
1. The template is based on an HTML file so requires the standard HTML structure.

2. Each part that would contain content is instead replaced by a placeholder enclosed in double curly braces `{{ }}`. These placeholders are replaced with actual values when the template is rendered.

Expand Down

0 comments on commit 019707d

Please sign in to comment.