### Clone and Initialize Plain Starter Kit
Source: https://plainframework.com/start/
This snippet demonstrates how to clone the bare starter kit repository, initialize a new Git repository, and run the development server. It's the quickest way to start a new project with the Plain framework.
```shell
git clone --depth 1 https://github.com/dropseed/plain-starter-bare new-project
cd new-project
rm -rf .git
git init
./scripts/install
uv run plain dev
```
--------------------------------
### Clone and Initialize Plain Starter App
Source: https://plainframework.com/start/
Clones the Plain starter application repository, initializes a new Git repository, and runs the development server using uv and the 'plain dev' command. This is the recommended way to start a new Plain project.
```shell
git clone --depth 1 https://github.com/dropseed/plain-starter-app new-project
cd new-project
rm -rf .git
git init
./scripts/install
uv run plain dev
```
--------------------------------
### Heroku Procfile Configuration
Source: https://plainframework.com/start/
Defines the commands that Heroku will run to start the web process and execute release tasks. It uses Gunicorn for the web server and Plain commands for pre-deployment checks and migrations.
```shell
web: gunicorn plain.wsgi:app
release: plain preflight --deploy --fail-level WARNING && plain migrate && plain chores run
```
--------------------------------
### Initialize Sentry SDK
Source: https://plainframework.com/start/
Initializes the Sentry SDK with configuration loaded from a script element. This snippet is crucial for error tracking and reporting in the application.
```javascript
var sentryInit = JSON.parse(document.getElementById("sentry\_init").textContent);
Sentry.onLoad(function() {
Sentry.init(sentryInit);
});
```
--------------------------------
### Basic Plain Project Structure
Source: https://plainframework.com/start/
Illustrates a standard directory layout for a Plain framework project. It typically includes a pyproject.toml file and an 'app' directory containing settings and URL configurations.
```text
your_repo/
├── pyproject.toml
└── app/
├── __init__.py
├── settings.py
└── urls.py
```
--------------------------------
### Combined Deployment Commands
Source: https://plainframework.com/start/
A sequence of commands for a typical production deployment. It includes preflight checks, database migrations, running maintenance tasks, and building static assets.
```shell
plain preflight --deploy --fail-level WARNING && \
plain migrate && \
plain chores run
```
--------------------------------
### Build Static Assets for Production
Source: https://plainframework.com/start/
Compiles and gathers static assets from various packages into a unified location for production deployment. This command is essential for serving assets efficiently.
```shell
plain build
```
--------------------------------
### Running Plain Application with Gunicorn
Source: https://plainframework.com/start/
This command shows how to run a Plain web application in production using Gunicorn, a WSGI HTTP Server. It points Gunicorn to the application instance provided by Plain.
```shell
gunicorn plain.wsgi:app
```
--------------------------------
### Plain Framework Preflight Checks for Deployment
Source: https://plainframework.com/start/
Executes pre-deployment checks for the Plain framework. The `--deploy` flag ensures checks are suitable for production, and `--fail-level WARNING` sets the threshold for critical failures.
```shell
plain preflight --deploy --fail-level WARNING
```
--------------------------------
### Plain Framework Dependencies in pyproject.toml
Source: https://plainframework.com/start/
Configuration for managing project dependencies using pyproject.toml. It specifies the required Python version, core 'plain' package, and development dependencies like 'plain.dev' using uv.
```toml
[project]
requires-python = ">=3.11"
dependencies = [
"plain",
]
[tool.uv]
dev-dependencies = [
"plain.dev",
]
```
--------------------------------
### Install plain-oauth Package
Source: https://plainframework.com/docs/plain-oauth/plain/oauth/README
Installs the plain-oauth library using pip. This is the first step to integrate OAuth functionality into your project.
```sh
pip install plain-oauth
```
--------------------------------
### Flask Quickstart: A Minimal Application
Source: https://flask.palletsprojects.com/en/stable/
This snippet demonstrates the most basic Flask application structure. It initializes a Flask app and defines a single route that returns a 'Hello, World!' message.
```Python
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
```
--------------------------------
### Install plain.admin Package
Source: https://plainframework.com/docs/plain-admin/plain/admin/README
Command to install the plain.admin package and its dependencies using the 'uv' package manager.
```console
uv add plain.admin
```
--------------------------------
### Configure plain.auth Installation
Source: https://plainframework.com/docs/plain-auth/plain/auth/README
Shows how to add `plain.auth` and related packages to `INSTALLED_PACKAGES` and configure middleware and user model settings in `app/settings.py`.
```python
# app/settings.py
INSTALLED_PACKAGES = [
# ...
"plain.auth",
"plain.sessions",
"plain.passwords",
]
MIDDLEWARE = [
"plain.sessions.middleware.SessionMiddleware",
"plain.auth.middleware.AuthenticationMiddleware",
]
AUTH_USER_MODEL = "users.User"
AUTH_LOGIN_URL = "login"
```
--------------------------------
### Flask Quickstart: Deploying to a Web Server
Source: https://flask.palletsprojects.com/en/stable/
This section outlines considerations for deploying Flask applications to production environments, often involving WSGI servers like Gunicorn or uWSGI.
```APIDOC
Deployment:
- Use a production-ready WSGI server (e.g., Gunicorn, uWSGI).
- Configure a reverse proxy (e.g., Nginx, Apache).
- Manage application configuration and secrets securely.
- Consider containerization (e.g., Docker).
```
--------------------------------
### Manually Invoke Plain Setup
Source: https://plainframework.com/docs/plain/plain/runtime/README
Shows how to manually set up the Plain runtime environment in a standalone Python script.
```python
import plain.runtime
plain.runtime.setup()
```
--------------------------------
### Configure Google Analytics (gtag)
Source: https://plainframework.com/start/
Sets up Google Analytics tracking by initializing the dataLayer and configuring the gtag script with the provided measurement ID. This enables website analytics.
```javascript
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-CC4CYKYT4F');
```
--------------------------------
### Install plain.tailwind Package
Source: https://plainframework.com/docs/plain-tailwind/plain/tailwind/README
Demonstrates how to add the `plain.tailwind` package to your project's installed packages, typically within a settings file.
```python
# settings.py
INSTALLED_PACKAGES = [
# ...
"plain.tailwind",
]
```
--------------------------------
### Initialize Codeplus Component
Source: https://plainframework.com/start/
Initializes the Codeplus component on page load, targeting elements with the '.highlight' class. It configures tab selection behavior and custom styling classes for UI elements.
```javascript
window.addEventListener("load", function() {
new Codeplus({
selector: ".highlight",
rememberTabSelections: false,
instanceClass: "group"
// ... other configuration options
}).render();
});
```
--------------------------------
### Install plain.elements
Source: https://plainframework.com/docs/plain-elements/plain/elements/README
Shows how to install the `plain.elements` package using pip and add it to the `INSTALLED_PACKAGES` setting in a Python project's settings file. This enables the Jinja extension automatically.
```python
# settings.py
INSTALLED_PACKAGES = [
# ...
"plain.elements",
]
```
--------------------------------
### Flask Quickstart: Using Flask Extensions
Source: https://flask.palletsprojects.com/en/stable/
Flask's design encourages the use of extensions to add features like database integration, authentication, and more. Extensions are typically initialized with the Flask app instance.
```Python
# Example with Flask-SQLAlchemy (not included in base Flask)
# from flask_sqlalchemy import SQLAlchemy
# db = SQLAlchemy()
# db.init_app(app)
# In a real scenario, you would import and initialize extensions here.
```
--------------------------------
### Plain Shell Auto-load Example
Source: https://plainframework.com/docs/plain/plain/cli/README
Demonstrates how to auto-load models or run code when launching the Plain Python shell by creating an `app/shell.py` file. This file is automatically imported by Plain.
```python
# app/shell.py
from app.organizations.models import Organization
__all__ = [
"Organization",
]
```
--------------------------------
### Configure Package Settings with Environment Variables
Source: https://plainframework.com/docs/plain/plain/runtime/README
Example of configuring package-specific settings, including database connection details, by checking environment variables.
```python
# plain/models/default_settings.py
from os import environ
from . import database_url
# Make DATABASE a required setting
DATABASE: dict
# Automatically configure DATABASE if a DATABASE_URL was given in the environment
if "DATABASE_URL" in environ:
DATABASE = database_url.parse_database_url(
environ["DATABASE_URL"],
# Enable persistent connections by default
conn_max_age=int(environ.get("DATABASE_CONN_MAX_AGE", 600)),
conn_health_checks=environ.get("DATABASE_CONN_HEALTH_CHECKS", "true").lower()
in [
"true",
"1",
],
)
```
--------------------------------
### Install plain.observer with uv
Source: https://plainframework.com/docs/plain-observer/plain/observer/README
Installs the plain.observer package using the uv package manager. This is the first step to integrate observability into your Plain application.
```bash
uv add plain.observer
```
--------------------------------
### Python: Install Plain Cache
Source: https://plainframework.com/docs/plain-cache/plain/cache/README
Shows how to integrate the `plain.cache` module into your project by adding it to the `INSTALLED_PACKAGES` list in your application's settings file.
```python
# app/settings.py
INSTALLED_PACKAGES = [
# ...
"plain.cache",
]
```
--------------------------------
### Using app_logger
Source: https://plainframework.com/docs/plain/plain/logs/README
Demonstrates how to use the pre-configured `app_logger` for basic logging within application code. It shows a simple example of logging an informational message.
```python
from plain.logs import app_logger
def example_function():
app_logger.info("Hey!")
```
--------------------------------
### Heroku Post Compile Script for Asset Building
Source: https://plainframework.com/start/
A bash script executed by Heroku's Python buildpack after compilation. It runs the 'plain build' command to prepare static assets for the deployed application.
```shell
#!/bin/bash -e
plain build
```
--------------------------------
### Lazy Fragment Rendering Example
Source: https://plainframework.com/docs/plain-htmx/plain/htmx/README
An example of an HTML template using a lazy fragment that iterates over context variables provided by a callable function, demonstrating asynchronous content loading.
```html
{% htmxfragment "main" lazy=True %}
{% for item in items %}
{{ item }}
{% endfor %}
{% endhtmxfragment %}
```
--------------------------------
### plain dev Command Overview
Source: https://plainframework.com/docs/plain-dev/plain/dev/README
The `plain dev` command is the central tool for managing local development environments. It automates setup, runs the application server, and integrates with other development tools.
```APIDOC
plain dev
Description:
Runs the local development server and associated services.
Functionality:
- Sets PLAIN_CSRF_TRUSTED_ORIGINS to localhost by default.
- Executes `plain preflight` to check for issues.
- Runs pending model migrations.
- Starts `gunicorn` with `--reload`.
- Serves HTTPS on port 8443 by default (or the next free port).
- Runs `plain tailwind build --watch` if `plain.tailwind` is installed.
- Executes custom processes defined in `pyproject.toml` at `tool.plain.dev.run`.
- Starts necessary services (e.g., Postgres) defined in `pyproject.toml` at `tool.plain.dev.services`.
Related Commands:
- `plain dev services`: Starts services independently.
- `plain dev logs`: Displays output from recent `plain dev` runs.
- `plain pre-commit`: Manages pre-commit hooks.
```
--------------------------------
### Example HTML Template Structure
Source: https://plainframework.com/docs/plain/plain/templates/README
An example of an HTML template file that extends a base template and displays dynamic content passed from the view context. It utilizes Jinja's templating syntax for blocks and variable interpolation.
```html
{% extends "base.html" %}
{% block content %}
{{ message }}
{% endblock %}
```
--------------------------------
### plain pre-commit Command
Source: https://plainframework.com/docs/plain-dev/plain/dev/README
Installs and runs a built-in pre-commit hook. It executes a series of checks and build steps to ensure code quality and consistency before commits.
```bash
plain pre-commit --install
```
```APIDOC
plain pre-commit
Description:
Installs and runs pre-commit hooks.
Executes:
- Custom commands defined in `pyproject.toml` at `tool.plain.pre-commit.run`.
- `plain code check`, if `plain.code` is installed.
- `uv lock --locked`, if using uv.
- `plain preflight --database default`.
- `plain migrate --check`.
- `plain makemigrations --dry-run --check`.
- `plain build`.
- `plain test`.
```
--------------------------------
### Flask Quickstart: Rendering Templates
Source: https://flask.palletsprojects.com/en/stable/
Flask uses Jinja2 for templating. The render_template function loads a Jinja2 template and renders it with context variables.
```Python
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/hello/')
@app.route('/hello/')
def hello(name=None):
return render_template('hello.html', name=name)
```
--------------------------------
### Add plain.models to INSTALLED_PACKAGES
Source: https://plainframework.com/docs/plain-models/plain/models/README
Shows how to install the plain.models library and include it in the INSTALLED_PACKAGES setting within the application's settings file.
```Python
# app/settings.py
INSTALLED_PACKAGES = [
...
"plain.models",
]
```
--------------------------------
### Configure Application Settings
Source: https://plainframework.com/docs/plain/plain/runtime/README
Defines core application settings like URL routers, time zones, installed packages, authentication, and middleware in `app/settings.py`.
```python
# app/settings.py
URLS_ROUTER = "app.urls.AppRouter"
TIME_ZONE = "America/Chicago"
INSTALLED_PACKAGES = [
"plain.models",
"plain.tailwind",
"plain.auth",
"plain.passwords",
"plain.sessions",
"plain.htmx",
"plain.admin",
"plain.elements",
# Local packages
"app.users",
]
AUTH_USER_MODEL = "users.User"
AUTH_LOGIN_URL = "login"
MIDDLEWARE = [
"plain.sessions.middleware.SessionMiddleware",
"plain.auth.middleware.AuthenticationMiddleware",
"plain.admin.AdminMiddleware",
]
```
--------------------------------
### Flask Quickstart: Redirects and Errors
Source: https://flask.palletsprojects.com/en/stable/
Flask provides functions to redirect users to other URLs or to abort requests with specific HTTP error codes.
```Python
from flask import abort, redirect, url_for
@app.route('/user/')
def get_user(id):
if id == 'admin':
abort(404)
return f'User ID: {id}'
@app.route('/')
def index():
return redirect(url_for('hello', name='Guest'))
```
--------------------------------
### plain dev Services Configuration
Source: https://plainframework.com/docs/plain-dev/plain/dev/README
Defines external services required for local development, such as databases or background processes. These services are automatically started by `plain dev` and `plain pre-commit`.
```toml
# pyproject.toml
[tool.plain.dev.services]
postgres = {cmd = "docker run --name app-postgres --rm -p 54321:5432 -v $(pwd)/.plain/dev/pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=postgres postgres:15 postgres"}
```
--------------------------------
### Flask Quickstart: Static Files
Source: https://flask.palletsprojects.com/en/stable/
Flask can serve static files like CSS, JavaScript, and images. These files are typically placed in a 'static' folder in the application's root directory.
```Python
from flask import url_for
# In a template, you would use:
#
#
```
--------------------------------
### Configure Plain Admin in Settings
Source: https://plainframework.com/docs/plain-admin/plain/admin/README
Example Python code showing how to configure the 'plain.admin' package within the application's settings, including necessary dependencies and middleware.
```python
# app/settings.py
INSTALLED_PACKAGES = [
"plain.models",
"plain.tailwind",
"plain.auth",
"plain.sessions",
"plain.htmx",
"plain.admin",
"plain.elements",
# other packages...
]
AUTH_USER_MODEL = "users.User"
AUTH_LOGIN_URL = "login"
MIDDLEWARE = [
"plain.sessions.middleware.SessionMiddleware",
"plain.auth.middleware.AuthenticationMiddleware",
"plain.admin.AdminMiddleware",
]
```
--------------------------------
### Flask Quickstart: Logging
Source: https://flask.palletsprojects.com/en/stable/
Flask integrates with Python's standard logging library. You can configure loggers, handlers, and formatters to capture application events and errors.
```Python
import logging
logging.basicConfig(level=logging.INFO)
@app.route('/log')
def log_something():
app.logger.info('This is an informational log message.')
return 'Logged a message.'
```
--------------------------------
### Define a Basic Plain View
Source: https://plainframework.com/docs/plain/plain/views/README
Demonstrates the fundamental structure of a Plain Framework View class, inheriting from `plain.views.View` and implementing a `get` method to handle requests.
```python
from plain.views import View
class ExampleView(View):
def get(self):
return "Hello, world!"
```
--------------------------------
### Run plain.oauth Migrations
Source: https://plainframework.com/docs/plain-oauth/plain/oauth/README
Applies database migrations for the plain.oauth application, setting up necessary database tables.
```sh
python manage.py migrate plain.oauth
```
--------------------------------
### Toggle Theme
Source: https://plainframework.com/start/
Adds an event listener to a theme toggle button. It switches between 'dark' and 'light' themes based on the current setting stored in localStorage and updates the document's data-theme attribute.
```javascript
window.addEventListener("load", function() {
document.querySelector("[data-toggle-theme]").addEventListener("click", function() {
const currentTheme = document.documentElement.dataset.theme;
const newTheme = currentTheme === "dark" ? "light" : "dark";
document.documentElement.dataset.theme = newTheme;
localStorage.theme = newTheme;
});
});
```
--------------------------------
### Flask Quickstart: Routing
Source: https://flask.palletsprojects.com/en/stable/
Routes map URLs to Python functions. This example shows how to define a route with a variable part, which is passed as an argument to the view function.
```Python
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Index Page'
@app.route('/hello/')
def hello(name):
return f'Hello, {name}!'
```
--------------------------------
### Use testbrowser fixture with Playwright
Source: https://plainframework.com/docs/plain-pytest/plain/pytest/README
Illustrates the usage of the `testbrowser` fixture, a Playwright wrapper for browser testing. It starts a gunicorn process to serve the application, allowing the browser to navigate and interact with the site. If `plain.models` is installed, it also integrates the `isolated_db` fixture by passing a `DATABASE_URL`.
```python
def test_example(testbrowser):
page = testbrowser.new_page()
page.goto('/')
assert page.title() == 'Home Page'
```
--------------------------------
### Flask Deployment Overview
Source: https://flask.palletsprojects.com/en/stable/
Provides guidance on deploying Flask applications to production environments. Covers different hosting options and strategies.
```APIDOC
Deploying to Production:
Self-Hosted Options:
Information on deploying Flask applications on your own servers or infrastructure.
Hosting Platforms:
Guidance on deploying to various cloud hosting platforms and services.
```
--------------------------------
### Install plain.flags
Source: https://plainframework.com/docs/plain-flags/plain/flags/README
Provides the necessary configuration to install the `plain.flags` package within a Django project. This involves adding the app to the `INSTALLED_APPS` setting.
```python
INSTALLED_PACKAGES = [
...
"plain.flags",
]
```
--------------------------------
### Access Runtime Settings
Source: https://plainframework.com/docs/plain/plain/runtime/README
Demonstrates how to access application settings at runtime using `plain.runtime.settings`.
```python
from plain.runtime import settings
print(settings.AN_EXAMPLE_SETTING)
```
--------------------------------
### Include Package Routers
Source: https://plainframework.com/docs/plain/plain/urls/README
Demonstrates how to include URL routers from installed packages into the main application router using `plain.urls.include`.
```python
# plain/assets/urls.py
from plain.urls import Router, path
from .views import AssetView
class AssetsRouter(Router):
"""
The router for serving static assets.
Include this router in your app router if you are serving assets yourself.
"""
namespace = "assets"
urls = [
path("", AssetView, name="asset"),
]
```
```python
from plain.urls import include, Router
from plain.assets.urls import AssetsRouter
class AppRouter(Router):
namespace = ""
urls = [
include("assets/", AssetsRouter),
# Your other URLs here...
]
```
--------------------------------
### Flask Templates: Jinja Setup
Source: https://flask.palletsprojects.com/en/stable/
Flask uses Jinja2 as its default templating engine. Templates are typically stored in a 'templates' folder.
```Python
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
```
--------------------------------
### Flask Extension Development Overview
Source: https://flask.palletsprojects.com/en/stable/
Provides guidelines and best practices for developing extensions for the Flask framework. Covers initialization, configuration, and integration.
```APIDOC
Flask Extension Development:
Naming:
Recommendations for naming Flask extensions.
The Extension Class and Initialization:
Details on creating an extension class and handling initialization with the Flask application.
Adding Behavior:
Techniques for extending Flask's functionality, such as adding new routes, template functions, or context processors.
Configuration Techniques:
Methods for managing configuration within extensions.
Data During a Request:
How extensions can manage data that is specific to a single request.
Views and Models:
Guidance on integrating views and data models within extensions.
Recommended Extension Guidelines:
A summary of best practices for creating robust and user-friendly Flask extensions.
```
--------------------------------
### Plain Core Modules Overview
Source: https://context7_llms
Lists the core modules available in the 'plain' package, which provide essential web request handling functionalities.
```APIDOC
Plain Core Modules:
- assets: Serve static files and assets.
- cli: The 'plain' CLI, powered by Click.
- csrf: Cross-Site Request Forgery protection.
- forms: HTML forms and form validation.
- http: HTTP request and response handling.
- logs: Logging configuration and utilities.
- preflight: Preflight checks for your app.
- runtime: Runtime settings and configuration.
- templates: Jinja2 templates and rendering.
- test: Test utilities and fixtures.
- urls: URL routing and request dispatching.
- views: Class-based views and request handlers.
```
--------------------------------
### Define Application URL Router
Source: https://plainframework.com/docs/plain/plain/urls/README
Example of defining the main `AppRouter` class in `app/urls.py`, inheriting from `plain.urls.Router` and including other routers and paths.
```python
# app/urls.py
from plain.urls import Router, path, include
from plain.admin.urls import AdminRouter
from . import views
class AppRouter(Router):
namespace = ""
urls = [
include("admin/", AdminRouter),
path("about/", views.AboutView, name="about"), # A named URL
path("", views.HomeView), # An unnamed URL
]
```
--------------------------------
### Plain Auth Packages Overview
Source: https://context7_llms
Outlines the authentication and authorization packages provided by Plain, covering user management, OAuth, password handling, and passwordless login.
```APIDOC
Plain Auth Packages:
- plain.auth: User authentication and authorization.
- plain.oauth: OAuth authentication and API access.
- plain.passwords: Password-based login and registration.
- plain.loginlink: Login links for passwordless authentication.
```
--------------------------------
### Plain Foundational Packages Overview
Source: https://context7_llms
Details the foundational packages that extend Plain's capabilities, focusing on data persistence, caching, email, sessions, and background jobs.
```APIDOC
Plain Foundational Packages:
- plain.models: Define and interact with your database models.
- plain.cache: A database-driven general purpose cache.
- plain.email: Send emails with SMTP or custom backends.
- plain.sessions: User sessions and cookies.
- plain.worker: Background jobs stored in the database.
- plain.api: Build APIs with Plain views.
```
--------------------------------
### Configure Database via Environment Variable
Source: https://plainframework.com/docs/plain-models/plain/models/README
Illustrates setting up a database connection by providing a DATABASE_URL environment variable, commonly used for PostgreSQL.
```Shell
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
```
--------------------------------
### Flask Quickstart: Accessing Request Data
Source: https://flask.palletsprojects.com/en/stable/
The request object provides access to incoming request data, such as form data, query parameters, and headers.
```Python
from flask import request
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
# Process login form data
username = request.form['username']
return f'Hello, {username}!'
return '''
'''
```
--------------------------------
### Flask Quickstart: Hooking in WSGI Middleware
Source: https://flask.palletsprojects.com/en/stable/
Flask applications can be wrapped with WSGI middleware to add functionality like request logging or session management.
```Python
from werkzeug.middleware.profiler import ProfilerMiddleware
# Example: Wrap the app with ProfilerMiddleware
# app.wsgi_app = ProfilerMiddleware(app.wsgi_app, profile_dir=None)
# The actual application object is app.wsgi_app
```
--------------------------------
### Configure INSTALLED_PACKAGES
Source: https://plainframework.com/docs/plain-oauth/plain/oauth/README
Configures the Django project to recognize the plain.oauth application by adding it to the INSTALLED_PACKAGES setting in settings.py.
```python
INSTALLED_PACKAGES = [
...
"plain.oauth",
]
```
--------------------------------
### Flask Quickstart: Debug Mode
Source: https://flask.palletsprojects.com/en/stable/
Enabling debug mode provides helpful error messages and automatic reloader for development. It should not be used in production environments.
```Python
if __name__ == '__main__':
app.run(debug=True)
```
--------------------------------
### Run migrations for plain.observer
Source: https://plainframework.com/docs/plain-observer/plain/observer/README
Executes database migrations to set up the necessary tables for the plain.observer package. This command should be run after configuring the package.
```bash
plain migrate
```
--------------------------------
### Plain Admin Packages Overview
Source: https://context7_llms
Describes the administrative packages for managing back-office tasks, including feature flags, redirects, page view tracking, and customer support.
```APIDOC
Plain Admin Packages:
- plain.admin: An admin interface for back-office tasks.
- plain.flags: Feature flags.
- plain.support: Customer support forms.
- plain.redirection: Redirects managed in the database.
- plain.pageviews: Basic self-hosted page view tracking and reporting.
- plain.observer: On-page telemetry reporting.
```
--------------------------------
### Flask Quickstart: Message Flashing
Source: https://flask.palletsprojects.com/en/stable/
Message flashing allows you to display short messages to the user after a redirect. These messages are stored in the session and can be retrieved in templates.
```Python
from flask import flash, redirect, url_for, render_template_string
@app.route('/flash')
def flash_message():
flash('This is a test message.')
return redirect(url_for('show_flash'))
@app.route('/show')
def show_flash():
return render_template_string('''
{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
{{ message }}
{% endfor %}
{% endif %}
{% endwith %}
''')
```
--------------------------------
### Add plain.htmx to Installed Packages
Source: https://plainframework.com/docs/plain-htmx/plain/htmx/README
Illustrates how to include the `plain.htmx` package in your project's `INSTALLED_PACKAGES` list to enable its features.
```python
INSTALLED_PACKAGES = [
# ...
"plain.htmx",
]
```
--------------------------------
### Add plain.worker to Installed Packages
Source: https://plainframework.com/docs/plain-worker/plain/worker/README
Illustrates how to include the `plain.worker` module in the `INSTALLED_PACKAGES` list within the application's settings file to enable its functionality.
```python
# app/settings.py
INSTALLED_PACKAGES = [
...
"plain.worker",
]
```
--------------------------------
### Run Deployment Preflight Checks
Source: https://plainframework.com/docs/plain/plain/preflight/README
Executes preflight checks, including those specific to production environments, by using the `--deploy` flag. This command is recommended to be part of your deployment process.
```bash
plain preflight --deploy
```
--------------------------------
### Plain Dev Packages Overview
Source: https://context7_llms
Highlights the development-focused packages that streamline local development, testing, code quality, and external access.
```APIDOC
Plain Dev Packages:
- plain.dev: A single command for local development.
- plain.pytest: Pytest fixtures and helpers.
- plain.code: Code formatting and linting.
- plain.tunnel: Expose your local server to the internet.
```