### Complete Sidewinder Configuration Example Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md A comprehensive example of a .env file containing all essential Sidewinder configuration variables. ```ini DJANGO_SECRET_KEY=secretkey DJANGO_DEBUG=1 DJANGO_DEBUG_TOOLBAR=1 DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1 DJANGO_SSL=0 DJANGO_SERVER_EMAIL=sidewinder@example.com DJANGO_EMAIL_HOST=example.emailprovider.com DJANGO_EMAIL_PORT=587 DJANGO_EMAIL_HOST_USER= DJANGO_EMAIL_HOST_PASSWORD= DJANGO_DEFAULT_FROM_EMAIL=sidewinder@example.com ALLAUTH_ACCOUNT_EMAIL_SUBJECT_PREFIX= DJ_DATABASE_CONN_STRING=postgres://postgres:postgres@localhost:5432/sidewinder REDIS_URL=redis://127.0.0.1:6379 ADMIN_EMAIL=youremail@example.com HUEY_DEV=1 ``` -------------------------------- ### Django Project Setup with Sidewinder Source: https://github.com/stribny/sidewinder/blob/master/README.md This snippet outlines the initial steps to set up a new Django project using the Sidewinder starter kit. It typically involves cloning the repository and installing dependencies. ```Shell git clone https://github.com/stribny/sidewinder.git cd sidewinder pip install -r requirements.txt ``` -------------------------------- ### Install Pre-commit Hooks with uv Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/installation.md Installs the pre-commit hooks for the project using the uv command-line tool. This ensures code quality and consistency. ```bash uv run -- pre-commit install ``` -------------------------------- ### Clone Sidewinder Repository Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/installation.md Clones the Sidewinder project locally from its GitHub repository URL. ```bash git clone https://github.com/stribny/sidewinder ``` -------------------------------- ### Install Playwright with uv Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/installation.md Installs Playwright, a browser automation tool, using the uv command. This is a prerequisite for certain development functionalities. ```bash uv run -- playwright install ``` -------------------------------- ### Development Tools Setup with Ruff and Django Extensions Source: https://github.com/stribny/sidewinder/blob/master/docs/index.md This configuration outlines the setup for development tools like Ruff for code formatting and linting, and Django extensions for enhanced Django management commands. ```INI [tool.ruff] line-length = 88 select = [ "E", "F", "I", "UP", ] ignore = [] [tool.ruff.format] quote-style = "double" [tool.ruff.lint] select = [ "B", "C", "E", "F", "I", "N", "PL", "T20", "UP", "W", ] ignore = [ "E501", # line too long, handled by ruff format "N806", # variable in function should be snake case ] [tool.django-extensions] SHELL_PLUS = "ipython" ``` -------------------------------- ### Django REST Framework API Setup Source: https://github.com/stribny/sidewinder/blob/master/README.md Sidewinder includes Django REST Framework from the start, providing features like standardized API documentation, error responses, and CORS configuration for building modern APIs. ```Python INSTALLED_APPS = [ # ... 'rest_framework', 'rest_framework.authtoken', 'corsheaders', # ... ] MIDDLEWARE = [ # ... 'corsheaders.middleware.CorsMiddleware', # ... ] REST_FRAMEWORK = { 'DEFAULT_RENDERER_CLASSES': [ 'rest_framework.renderers.JSONRenderer', ], 'DEFAULT_PARSER_CLASSES': [ 'rest_framework.parsers.JSONParser', ], 'DEFAULT_AUTHENTICATION_CLASSES': [ 'rest_framework.authentication.TokenAuthentication', ], 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.IsAuthenticated', ], } ``` -------------------------------- ### Testing Setup with Pytest and Faker Source: https://github.com/stribny/sidewinder/blob/master/docs/index.md This snippet details the testing configuration using pytest and its plugins, along with Faker for generating test data. It includes common plugins for enhanced testing capabilities. ```Python INSTALLED_APPS = [ # ... "pytest", "pytest_django", "factory", "faker", # ... ] # pytest configuration (e.g., in pytest.ini or pyproject.toml) # [pytest] # addopts = --cov=my_project --cov-report=term-missing # Example usage of factoryboy and faker in tests: # from django.contrib.auth import get_user_model # from factory import django, fuzzy # from faker import Faker # User = get_user_model() # fake = Faker() # class UserFactory(django.DjangoModelFactory): # class Meta: # model = User # username = factory.LazyFunction(fake.user_name) # email = factory.LazyFunction(fake.email) # is_staff = False ``` -------------------------------- ### Configure GeoDjango PostGIS Backend Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md Sets the database backend to Django's PostGIS extension for geospatial data. Requires PostGIS to be installed and enabled in the database. ```ini DJANGO_DATABASE_BACKEND=django.contrib.gis.db.backends.postgis ``` -------------------------------- ### Configure Django Allowed Hosts Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md Specifies the host/domain names that this Django site can serve. Essential for production security. ```ini DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1 ``` -------------------------------- ### Configure Database Connection String Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md Specifies the database connection string for SQLite or PostgreSQL. Supports standard connection string formats and GeoDjango with PostGIS. ```ini DJ_DATABASE_CONN_STRING=postgres://postgres:postgres@localhost:5432/sidewinder ``` -------------------------------- ### Monitor Server Resources with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Starts a system monitor to track server resource usage, including memory, disk space, and CPU utilization. ```makefile make monitor ``` -------------------------------- ### Create and Start New Django App Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/create-app.md This snippet demonstrates how to create a new directory for your Django app and then use the `manage.py startapp` command to generate the app's structure. It specifies the new app name and its location within the project's app folder. ```Shell # inside virtual env in the project's root folder mkdir / ./manage.py startapp / ``` -------------------------------- ### Enable SMTP Development Email Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md Enables the use of an SMTP backend for sending emails in development, useful for testing email functionality. ```ini SMTP_DEV=1 ``` -------------------------------- ### Configure Django Secret Key Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md Sets the secret key for Django. This is crucial for security in production environments. ```ini DJANGO_SECRET_KEY=secretkey ``` -------------------------------- ### Configure Django SSL Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md Enables or disables SSL (HTTPS) for the Django application. Set to '1' for production environments. ```ini DJANGO_SSL=0 ``` -------------------------------- ### Rename Application Folder using Sed and Mv Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md Provides Bash commands to rename the application folder and update all internal references from 'appname' to a new name (e.g., 'myapp'). ```bash sed -i 's/appname\. /myapp\./g' `grep 'appname\.' -rl *` mv appname/ myapp/ ``` -------------------------------- ### Configure Huey Development Mode Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md Controls Huey's behavior in development. Set to '1' (default) to avoid using Redis, or '0' to require a running Redis instance. ```ini HUEY_DEV=1 ``` -------------------------------- ### Configure Redis URL Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md Specifies the connection URL for the Redis instance used by Sidewinder for background tasks. Defaults to localhost:6379. ```ini REDIS_URL=redis://127.0.0.1:6379 ``` -------------------------------- ### Configure Django Email Settings Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md Sets up email server details, including the server address, port, username, and password. Also configures the default sender email and email subject prefix for allauth. ```ini DJANGO_SERVER_EMAIL=sidewinder@example.com DJANGO_EMAIL_HOST=example.emailprovider.com DJANGO_EMAIL_PORT=587 DJANGO_EMAIL_HOST_USER= DJANGO_EMAIL_HOST_PASSWORD= DJANGO_DEFAULT_FROM_EMAIL=sidewinder@example.com ALLAUTH_ACCOUNT_EMAIL_SUBJECT_PREFIX= ``` -------------------------------- ### Configure Admin Email Address Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md Sets an email address for receiving periodic task reports. Useful for verifying that background tasks are executing correctly. ```ini ADMIN_EMAIL=youremail@example.com ``` -------------------------------- ### Configure Django Debug Mode Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/configuration.md Enables or disables Django's debug mode and the debug toolbar. Set to '1' for development and '0' for production. ```ini DJANGO_DEBUG=1 DJANGO_DEBUG_TOOLBAR=1 ``` -------------------------------- ### Deployment with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/index.md This outlines the components involved in deploying the Sidewinder project using Ansible on a single VPS. It specifies the operating system, database, reverse proxy, and WSGI server. ```Shell # Ansible playbook (example structure) # hosts: your_vps_ip # become: yes # vars: # project_name: sidewinder # domain_name: your_domain.com # python_version: 3.10 # postgres_version: "14" # caddy_version: "2.6.4" # roles: # - common # - postgresql # - caddy # - gunicorn # - project_deployment # Example systemd service file for gunicorn: # [Unit] # Description=gunicorn daemon for sidewinder # After=network.target # [Service] # User=www-data # Group=www-data # WorkingDirectory=/path/to/your/project # ExecStart=/path/to/your/venv/bin/gunicorn --workers 3 --bind unix:/run/gunicorn.sock sidewinder.wsgi:application # [Install] # WantedBy=multi-user.target ``` -------------------------------- ### Deployment with Ansible Source: https://github.com/stribny/sidewinder/blob/master/README.md Sidewinder provides Ansible playbooks for simplified deployment to a single Virtual Private Server (VPS), following an 'It just works' philosophy. ```YAML - hosts: your_vps_ip become: yes roles: - common - python - django_app - nginx - postgresql ``` -------------------------------- ### Provision Server with Ansible Playbook Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/provisioning.md This command executes the Ansible playbook to provision the server. It assumes you are in the 'deployment/ansible' directory and have the 'make' command available. The playbook downloads and deploys the latest version from the master branch of your Git repository. ```bash cd deployment/ansible make provision ``` -------------------------------- ### Automated Testing with Pytest and FactoryBoy Source: https://github.com/stribny/sidewinder/blob/master/README.md The starter kit emphasizes automated testing using pytest, with efficient test fixture creation facilitated by factoryboy and Faker for generating realistic test data. ```Python import pytest from factory.fuzzy import FuzzyText from .models import MyModel from .factories import MyModelFactory def test_my_model_creation(): my_model = MyModelFactory() assert isinstance(my_model, MyModel) assert my_model.name == "" def test_factory_attributes(): my_model = MyModelFactory(name='Test Name') assert my_model.name == 'Test Name' ``` -------------------------------- ### Provision Server with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Provisions a Virtual Private Server (VPS) from scratch using Ansible. The APP_VERSION environment variable can be used to specify a particular application version for provisioning. ```makefile make provision ``` -------------------------------- ### List Backups with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Lists all available backups on the server. ```makefile make listbackups ``` -------------------------------- ### Huey Task Queue Integration Source: https://github.com/stribny/sidewinder/blob/master/docs/index.md This snippet demonstrates the configuration for Huey, a task queue system for Django. It includes settings for Huey's backend, persistence, and monitoring via django-huey-monitor. ```Python INSTALLED_APPS = [ # ... "huey", "huey_monitor", # ... ] HUEY = { "name": "Sidewinder", "results": True, "store_none": False, "permanent": False, "backend_path": "redis://localhost:6379/1", "consumer": { "workers": 4, "worker_type": "thread", "initial_delay": 0.1, "backoff": 1.1, "max_delay": 10.0, "graceful_exit": True, "check_interval": 1, "stop_on_signals": True, "pid_dir": None, "logfile": None, "log_level": "INFO", }, } ``` -------------------------------- ### Backup Database with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Creates a new backup of the database. ```makefile make dbbackup ``` -------------------------------- ### Backup Media Files with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Creates a new backup of the server's media files. ```makefile make mediabackup ``` -------------------------------- ### Create Superuser with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Creates a superuser account on the server. ```makefile make createsuperuser ``` -------------------------------- ### Environment Variable Configuration in Django Source: https://github.com/stribny/sidewinder/blob/master/README.md Sidewinder utilizes environment variables for configuration, simplifying the management of settings across different environments. This approach avoids the need for multiple configuration files. ```Python import os SECRET_KEY = os.environ.get('SECRET_KEY') DEBUG = os.environ.get('DEBUG', 'False').lower() in ('true', '1') DATABASE_URL = os.environ.get('DATABASE_URL') ``` -------------------------------- ### Deploy Application Version with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Deploys a new version of the application to the server using Ansible. Specify the application version using the APP_VERSION environment variable. ```makefile make deploy ``` -------------------------------- ### Upgrade System Packages with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Updates all operating system packages and restarts the server. ```makefile make upgrade ``` -------------------------------- ### Django REST Framework API Documentation with drf-spectacular Source: https://github.com/stribny/sidewinder/blob/master/docs/index.md This snippet showcases the integration of Django REST Framework with drf-spectacular for generating OpenAPI documentation. It also includes drf-standardized-errors for consistent API responses and django-cors-headers for managing cross-origin requests. ```Python INSTALLED_APPS = [ # ... "rest_framework", "drf_spectacular", "drf_standardized_errors", "django_cors_headers", # ... ] REST_FRAMEWORK = { "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", "DEFAULT_AUTHENTICATION_CLASSES": [ "rest_framework.authentication.TokenAuthentication", ], } SPECTACULAR_SETTINGS = { "TITLE": "My Sidewinder Project API", "DESCRIPTION": "API documentation for My Sidewinder Project", "VERSION": "1.0.0", "SERVE_INCLUDE_SCHEMA": False, } DRF_STANDARDIZED_ERRORS = { "ENABLE_IN_DEBUG_FOR_ALL_SETTINGS": True, "ENABLE_LOGGING": True, "LOGGING_ERRORS_TO_CALLBACK": True, } CORS_ALLOWED_ORIGINS = [ "http://localhost:3000", "http://127.0.0.1:3000", ] CORS_URLS_REGEX = r"^/api/.*$" ``` -------------------------------- ### Restore Media Files with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Restores the server's media files from the most recent backup. ```makefile make mediarestore ``` -------------------------------- ### MkDocs Documentation Commands Source: https://github.com/stribny/sidewinder/blob/master/docs/reference/commands.md Commands for serving and building the project's documentation site using MkDocs. These commands facilitate local development and deployment of documentation. ```Shell uv run -- mkdocs serve ``` ```Shell uv run -- mkdocs build ``` -------------------------------- ### Frontend End-to-End Testing with Playwright Source: https://github.com/stribny/sidewinder/blob/master/README.md Sidewinder includes Playwright for end-to-end testing of the frontend application, ensuring a robust user experience. ```JavaScript const { test, expect } = require('@playwright/test'); test('should navigate to the homepage', async ({ page }) => { await page.goto('http://localhost:8000/'); await expect(page).toHaveTitle(/Django/); }); test('should submit a form', async ({ page }) => { await page.goto('http://localhost:8000/form/'); await page.fill('input[name="name"]', 'Test User'); await page.click('button[type="submit"]'); await expect(page.locator('.success-message')).toContainText('Thank you'); }); ``` -------------------------------- ### Huey Task Queue Integration Source: https://github.com/stribny/sidewinder/blob/master/README.md Sidewinder integrates Huey for background and periodic task processing. This allows for asynchronous operations, improving application responsiveness. ```Python from huey import RedisHuey redis_client = RedisHuey('my-app', host='localhost', port=6379) @redis_client.task() def add(a, b): return a + b ``` -------------------------------- ### Restore Database with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Restores the database from the most recent backup. ```makefile make dbrestore ``` -------------------------------- ### Create Superuser with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/provisioning.md This command, executed within the 'deployment/ansible' directory, creates a superuser for the Django application deployed on the server. It relies on the Ansible playbook and the configurations in vars.yml. ```bash # inside deployment/ansible make createsuperuser ``` -------------------------------- ### View Web Server Access Logs with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Displays the most recent access logs for the web server. ```makefile make webserveraccesslog ``` -------------------------------- ### Access Database Shell with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Provides a remote shell to interact with the database server. ```makefile make dbshell ``` -------------------------------- ### Configure hosts.ini for Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/provisioning.md This snippet shows the format for the hosts.ini file used by Ansible to define server connection details. It requires specifying the hostname, the Ansible user, and the server's IP address. ```ini [all] host_name ansible_user=root ansible_host=29.38.208.180 ``` -------------------------------- ### View Application Service Logs with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Displays the most recent logs generated by the application service. ```makefile make appservicelog ``` -------------------------------- ### Deploy Specific Application Version Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/deployment.md Deploys a specific version of the application identified by a Git branch, tag, or commit hash. The version is specified using the APP_VERSION environment variable before executing the 'make deploy' command. ```bash # inside deployment/ansible APP_VERSION="v1.0" make deploy ``` -------------------------------- ### View Web Server Service Logs with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Displays the most recent logs generated by the web server service. ```makefile make webserverservicelog ``` -------------------------------- ### View Queue Service Logs with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Displays the most recent logs generated by the queue service. ```makefile make queueservicelog ``` -------------------------------- ### Check Server Service Status with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Retrieves the status of critical services running on the server, including the application, database, Redis, queue, and web server. ```makefile make status ``` -------------------------------- ### Deploy Master Branch Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/deployment.md Deploys the master branch of the application. This command assumes you are in the 'deployment/ansible' directory and have made updates to the application that need to be pushed to the remote Git repository. ```bash cd deployment/ansible make deploy ``` -------------------------------- ### SSH into Server with Ansible Source: https://github.com/stribny/sidewinder/blob/master/docs/howto/server-management.md Establishes a remote SSH shell connection to the server managed by Ansible. ```makefile make login ``` -------------------------------- ### Django Management Commands Source: https://github.com/stribny/sidewinder/blob/master/docs/reference/commands.md A collection of common Django management commands for tasks such as server management, database operations, migrations, shell access, and more. These commands are executed using `uv run -- manage.py`. ```Shell uv run -- manage.py runserver ``` ```Shell uv run -- manage.py fresh ``` ```Shell uv run -- manage.py makemigrations ``` ```Shell uv run -- manage.py migrate ``` ```Shell uv run -- manage.py sqlmigrate ``` ```Shell uv run -- manage.py sh ``` ```Shell uv run -- manage.py dbshell ``` ```Shell uv run -- manage.py run_huey ``` ```Shell uv run -- manage.py print_settings ``` ```Shell uv run -- manage.py diffsettings ``` ```Shell uv run -- manage.py show_urls ``` ```Shell uv run -- manage.py show_template_tags ``` ```Shell uv run -- manage.py list_signals ``` ```Shell uv run -- manage.py list_model_info ``` ```Shell uv run -- manage.py notes ``` ```Shell uv run -- manage.py inspectdb ``` ```Shell uv run -- manage.py spectacular ``` ```Shell uv run -- manage.py startapp / ``` ```Shell uv run -- manage.py createsuperuser ``` ```Shell uv run -- manage.py changepassword ``` ```Shell uv run -- manage.py generate_secret_key ``` ```Shell uv run -- manage.py admin_generator ``` ```Shell uv run -- manage.py describe_form ``` ```Shell uv run -- manage.py drf_create_token ``` ```Shell uv run -- manage.py makemessages --locale= ``` ```Shell uv run -- manage.py compilemessages ``` ```Shell uv run -- manage.py clear_cache ``` ```Shell uv run -- manage.py clean_pyc ``` ```Shell uv run -- manage.py check ``` ```Shell uv run -- manage.py validate_templates ``` ```Shell uv run -- manage.py unreferenced_files ``` ```Shell uv run -- manage.py sendtestemail ``` ```Shell uv run -- manage.py raise_test_exception ``` -------------------------------- ### Django Login Form Template Source: https://github.com/stribny/sidewinder/blob/master/templates/account/login.html This HTML template uses Django's template language to render a login form. It includes CSRF protection, form fields, and links to related account actions like signup and password reset. It also conditionally displays debug information if the 'debug' variable is true. ```html {% extends 'account/\_base.html' %} {% load i18n %} {% block title %}{% trans "Log in" %}{% endblock %} {% block content_auth_form %} {% trans "Log in" %} ==================== {% csrf_token %} {{ form }} {% trans "Log in" %} [{% trans "Create a new account" %}]({% url 'account_signup' %}) [{% trans "Forgot password?" %}]({% url 'account_reset_password' %}) {% if debug %} {% csrf_token %} {% trans "Log in as:" %} {% trans "Select user" %} {% for user in all_users %} {{ user.email }} {% endfor %} {% endif %} {% endblock content_auth_form %} ``` -------------------------------- ### Django Template for Email Confirmation Source: https://github.com/stribny/sidewinder/blob/master/templates/account/email_confirm.html This snippet shows the Django template used for email address confirmation. It extends a base template, loads necessary tags, and displays user-specific confirmation messages or instructions for issuing a new request if the link is invalid. ```html {% extends 'account/\_base.html' %} {% load i18n %} {% load account %} {% block title %}{% trans "Confirm e-mail address" %}{% endblock %} {% block content_auth_form %} {% trans "Confirm e-mail address" %} ==================================== {% if confirmation %} {% user_display confirmation.email_address.user as user_display %} {% blocktrans with confirmation.email_address.email as email %}Please confirm that [{{ email }}](mailto:{{ email }}) is your e-mail address.{% endblocktrans %} {% csrf_token %} {% trans 'Confirm' %} {% else %} {% url 'account_email' as email_url %} {% blocktrans %}This e-mail confirmation link expired or is invalid. Please [issue a new e-mail confirmation request]({{ email_url }}).{% endblocktrans %} {% endif %} {% endblock content_auth_form %} ``` -------------------------------- ### Password Reset Form (Django Template) Source: https://github.com/stribny/sidewinder/blob/master/templates/account/password_reset_from_key.html This Django template snippet handles the display of the password reset form. It includes CSRF token protection and renders the form fields. It also manages different states like invalid tokens and successful password changes. ```html {% extends 'account/\_base.html' %} {% load i18n %} {% block title %}{% translate "Change password" %}{% endblock %} {% block content_auth_form %} {% if token_fail %} {% translate "Invalid token" %} =============================== {% url 'account_reset_password' as the_url %} {% blocktranslate with the_url=the_url %}The password reset link was invalid. Perhaps it has already been used? Please request a [new password reset]({{ the_url }}).{% endblocktranslate %} {% else %} {% if form %} {% translate "Change password" %} ================================= {% csrf_token %} {{ form }} {% translate "Change password" %} {% else %} {% translate "All done!" %} =========================== {% translate "Your password is now changed." %} {% endif %} {% endif %} {% endblock content_auth_form %} ``` -------------------------------- ### URL for Password Reset (Django) Source: https://github.com/stribny/sidewinder/blob/master/templates/account/password_reset_from_key.html This snippet shows how to define and use a URL name for the password reset functionality in Django. It's used within the template to create a link for requesting a new password reset. ```python {% url 'account_reset_password' as the_url %} ``` -------------------------------- ### Django Template Renderer for Field/Label Positioning Source: https://github.com/stribny/sidewinder/blob/master/templates/django/forms/field.html This Django template snippet customizes the rendering of form fields. It conditionally displays labels, handles fieldsets, and manages the positioning of labels for checkboxes. It also includes logic for displaying help text and errors. ```Django Template {# This renderer switches the position of the field and label for checkboxes #} {% if field.use_fieldset %} {% if field.label %}{{ field.legend_tag }}{% endif %} {% else %} {% if field.label and field.widget_type != 'checkbox' %}{{ field.label_tag }}{% endif %} {% endif %} {% if field.help_text %} {{ field.help_text|safe }} {% endif %} {{ field.errors }} {{ field }} {% if field.widget_type == 'checkbox' and not field.use_fieldset %}{{ field.label_tag }}{% endif %} {% if field.use_fieldset %}{% endif %} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.