### Install Development Requirements and Pre-commit Hooks Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Navigate to your project directory and install development dependencies using uv. Initialize a git repository if one doesn't exist, as pre-commit requires it. ```bash cd uv sync git init # A git repo is required for pre-commit to install uv run pre-commit install ``` -------------------------------- ### Initialize Git and Install Pre-commit Hooks Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md Initializes a Git repository and installs pre-commit hooks locally. This is crucial to avoid CI and linter errors. ```bash git init pre-commit install ``` -------------------------------- ### Example Cookiecutter Prompts and Responses Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/README.md This is an example of the interactive prompts you will encounter when generating a project and the corresponding inputs. ```bash Cloning into 'cookiecutter-django'... remote: Counting objects: 550, done. remote: Compressing objects: 100% (310/310), done. remote: Total 550 (delta 283), reused 479 (delta 222) Receiving objects: 100% (550/550), 127.66 KiB | 58 KiB/s, done. Resolving deltas: 100% (283/283), done. project_name [My Awesome Project]: Reddit Clone project_slug [reddit_clone]: reddit description [Behold My Awesome Project!]: A reddit clone. author_name [Daniel Roy Greenfeld]: Daniel Greenfeld domain_name [example.com]: myreddit.com email [daniel-greenfeld@example.com]: pydanny@gmail.com version [0.1.0]: 0.0.1 Select open_source_license: 1 - MIT 2 - BSD 3 - GPLv3 4 - Apache Software License 2.0 5 - Not open source Choose from 1, 2, 3, 4, 5 [1]: 1 Select username_type: 1 - username 2 - email Choose from 1, 2 [1]: 1 timezone [UTC]: America/Los_Angeles windows [n]: n Select an editor to use. The choices are: 1 - None 2 - PyCharm 3 - VS Code Choose from 1, 2, 3 [1]: 1 use_docker [n]: n Select postgresql_version: 1 - 18 2 - 17 3 - 16 4 - 15 5 - 14 Choose from 1, 2, 3, 4 [1]: 1 Select cloud_provider: 1 - AWS 2 - GCP 3 - None Choose from 1, 2, 3 [1]: 1 Select mail_service: 1 - Mailgun 2 - Amazon SES 3 - Mailjet 4 - Mandrill 5 - Postmark 6 - Sendgrid 7 - Brevo (formerly SendinBlue) 8 - SparkPost 9 - Other SMTP Choose from 1, 2, 3, 4, 5, 6, 7, 8, 9 [1]: 1 Select rest_api [None]: 1 - None 2 - DRF 3 - Django Ninja Choose from 1, 2, 3 [1]: 1 use_async [n]: n Select frontend_pipeline: 1 - None 2 - Django Compressor 3 - Gulp 4 - Webpack Choose from 1, 2, 3, 4 [1]: 1 use_celery [n]: y use_mailpit [n]: n use_sentry [n]: y use_whitenoise [n]: n use_heroku [n]: y Select ci_tool: 1 - None 2 - Travis 3 - Gitlab 4 - Github Choose from 1, 2, 3, 4 [1]: 4 keep_local_envs_in_vcs [y]: y debug [n]: n ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-on-pythonanywhere.md Use this bash command to clone your project repository and install its dependencies using uv. ```bash git clone cd my-project-name uv sync --locked --no-dev # may take a few minutes ``` -------------------------------- ### Install JavaScript Dependencies Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Install project dependencies using npm. This is required before starting the development server with Webpack/Gulp. ```default npm install ``` -------------------------------- ### Start Development Server with Webpack/Gulp Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Start the development server, which simultaneously builds static assets using Webpack/Gulp and runs the Django server. Access the application at http://localhost:3000. ```default npm run dev ``` -------------------------------- ### Install Cookiecutter Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/README.md Install the cookiecutter tool using uv. Ensure you are using a version greater than or equal to 1.7.0. ```bash uv tool install "cookiecutter>=1.7.0" ``` -------------------------------- ### Run Docs and Local Services Together Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md Start both the local development services (Django, PostgreSQL) and the documentation service simultaneously. This allows for integrated development and testing. ```bash docker compose -f docker-compose.local.yml -f docker-compose.docs.yml up ``` -------------------------------- ### Example Local PostgreSQL Environment Variables Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md This snippet displays example environment variables for PostgreSQL, including host, database name, user, and password. ```dotenv # PostgreSQL # ------------------------------------------------------------------------------ POSTGRES_HOST=postgres POSTGRES_DB= POSTGRES_USER=XgOWtQtJecsAbaIyslwGvFvPawftNaqO POSTGRES_PASSWORD=jSljDz4whHuwO3aJIgVBrqEml5Ycbghorep4uVJ4xjDYQu0LfuTZdctj7y0YcCLu ``` -------------------------------- ### Start Documentation Service Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md Run only the documentation service using its specific Docker Compose file. This is useful for developing or viewing documentation independently. ```bash docker compose -f docker-compose.docs.yml up ``` -------------------------------- ### Start Local Development Services Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md Run the main Django and PostgreSQL services for local development. This command may take longer on the first execution. ```bash docker compose -f docker-compose.local.yml up ``` -------------------------------- ### Install Dependencies with uv Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/AGENTS.md Installs project dependencies using the uv package manager, ensuring all locked versions are used. ```bash uv sync --locked ``` -------------------------------- ### Start Mailpit Local SMTP Server Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/README.md Instructions for downloading, making executable, and running the Mailpit local SMTP server. Access the web interface at http://127.0.0.1:8025. ```bash chmod +x mailpit ./mailpit ``` -------------------------------- ### Subsequent Django Deployments on PythonAnywhere Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-on-pythonanywhere.md Use these commands in a Bash console for future deployments after the initial setup. Ensure you are in the project directory before running. ```bash cd project-directory git pull uv run python manage.py migrate uv run python manage.py compress # optional, if using django-compressor uv run python manage.py collectstatic ``` -------------------------------- ### Configure Database URL Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-on-pythonanywhere.md Set the DATABASE_URL environment variable in your .env file to connect to your PostgreSQL database. Ensure the format matches the provided example. ```bash DATABASE_URL='postgres://:@:/' ``` -------------------------------- ### Start Redis Server Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Start the Redis server in a terminal. This is necessary for Celery to function correctly when not running tasks eagerly. ```default redis-server ``` -------------------------------- ### Start Mailpit Server Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Start the Mailpit local email server in a separate terminal. Access it at http://127.0.0.1:8025/. ```default ./mailpit ``` -------------------------------- ### Run Production Docker Stack Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-with-docker.md Starts the Docker containers for the production environment. Use the '-d' flag to run in detached mode. ```bash docker compose -f docker-compose.production.yml up ``` ```bash docker compose -f docker-compose.production.yml up -d ``` -------------------------------- ### JavaScript WebSocket Usage Example Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/websocket.md Demonstrates how to establish a WebSocket connection, handle incoming messages, and send data using JavaScript. Ensure your project is configured with `use_async` to enable WebSocket support. ```javascript > ws = new WebSocket('ws://localhost:8000/') // or 'wss:///' in prod WebSocket {url: "ws://localhost:8000/", readyState: 0, bufferedAmount: 0, onopen: null, onerror: null, …} > ws.onmessage = event => console.log(event.data) event => console.log(event.data) > ws.send("ping") undefined pong! ``` -------------------------------- ### Example Translation String Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/locale/README.md A Portable Object (`.po`) file contains `msgid` (message ID) and `msgstr` (message string) pairs. Translate the `msgstr` for each `msgid`. ```po msgid "users" msgstr "utilisateurs" ``` -------------------------------- ### Apply Database Migrations Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Apply all pending database migrations to set up the database schema for your Django project. This command requires `uv` to be installed and active. ```bash uv run python manage.py migrate ``` -------------------------------- ### Rebuild and Start Docker Compose Services Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md After making configuration changes, rebuild your Docker application and start the services in detached mode using Docker Compose. This command ensures that all services are up-to-date with the latest configurations and running in the background. ```bash docker compose -f docker-compose.local.yml up -d --build ``` -------------------------------- ### Start Celery Beat Scheduler Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/README.md Run the Celery beat scheduler as a standalone process to manage periodic tasks. Ensure you are in the project's slug directory. ```bash cd {{cookiecutter.project_slug}} uv run celery -A config.celery_app beat ``` -------------------------------- ### Run Django Development Server (Synchronous) Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Start the Django development server for synchronous applications. This command serves the application on all available network interfaces on port 8000. ```bash uv run python manage.py runserver 0.0.0.0:8000 ``` -------------------------------- ### Start Celery Worker Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/README.md To run a Celery worker, navigate to your project's slug directory and execute this command. The worker will log information at the 'info' level. ```bash cd {{cookiecutter.project_slug}} uv run celery -A config.celery_app worker -l info ``` -------------------------------- ### Supervisor Configuration for Docker Compose Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-with-docker.md Example Supervisor configuration file to manage the Docker Compose stack. This ensures the application restarts automatically and survives system reboots. ```ini [program:{{cookiecutter.project_slug}}] command=docker compose -f docker-compose.production.yml up directory=/path/to/{{cookiecutter.project_slug}} redirect_stderr=true autostart=true autorestart=true priority=10 ``` -------------------------------- ### Run Uvicorn for Asynchronous Applications Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Start the Uvicorn server for asynchronous Django applications. This command enables hot-reloading for the server and includes HTML files in the reload process. ```bash uv run uvicorn config.asgi:application --host 0.0.0.0 --reload --reload-include '*.html' ``` -------------------------------- ### Start Celery Worker with Embedded Beat Scheduler Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/README.md Combines a Celery worker and the beat scheduler into a single process. This is not recommended for production environments. ```bash cd {{cookiecutter.project_slug}} uv run celery -A config.celery_app worker -B -l info ``` -------------------------------- ### Start Services in Detached Mode Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md Run Docker Compose services in the background. Use this when you want the services to continue running without keeping the terminal occupied. ```bash docker compose up -d ``` -------------------------------- ### Supervisor Control Commands Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-with-docker.md Commands to manage Supervisor, including rereading configuration, updating processes, and starting a specific program. Use these after placing the Supervisor configuration file. ```bash supervisorctl reread ``` ```bash supervisorctl update ``` ```bash supervisorctl start {{cookiecutter.project_slug}} ``` ```bash supervisorctl status ``` -------------------------------- ### Upgrade PostgreSQL Version - Final Steps Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/docker-postgres-backups.md Completes the PostgreSQL upgrade by rebuilding the postgres image, starting the container, restoring from backup, and bringing up all services. Ensure the PostgreSQL version in the Dockerfile is updated prior to this. ```bash $ docker compose -f docker-compose.local.yml build postgres ``` ```bash $ docker compose -f docker-compose.local.yml up -d postgres ``` ```bash $ docker compose -f docker-compose.local.yml run --rm postgres restore backup_2018_03_13T09_05_07.sql.gz ``` ```bash $ docker compose -f docker-compose.local.yml up -d ``` -------------------------------- ### Add 3rd Party Python Packages Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md To install a new 3rd party Python package, modify `pyproject.toml` in the Docker image. Rebuild the image and restart the container for changes to take effect. ```text "==" ``` ```bash docker compose -f docker-compose.local.yml build docker compose -f docker-compose.local.yml up ``` -------------------------------- ### Configure Celery to Use Broker Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Set Celery to use a broker (like Redis) instead of running tasks on the main thread locally. This requires Redis to be installed and running. ```python CELERY_TASK_ALWAYS_EAGER = False ``` -------------------------------- ### Generate Dependency Lockfile in Container Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md Runs the 'uv lock' command inside the Django container to generate a lockfile for reproducible dependency installation. This is necessary because Docker cannot write to the host system during builds. ```bash docker compose -f docker-compose.local.yml run –rm django uv lock ``` -------------------------------- ### Add Node.js Buildpack for Frontend Pipeline Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-on-heroku.md Command to add the Node.js buildpack to your Heroku application. This is required if you are using Gulp or Webpack for your frontend pipeline, allowing Heroku to run npm install and npm build during deployment. ```bash heroku buildpacks:add --index 1 heroku/nodejs ``` -------------------------------- ### Build and Serve HTML Documentation Locally Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/document.md Run this command from the project directory to build and serve HTML documentation when developing locally. ```bash make -C docs livehtml ``` -------------------------------- ### Build and Serve Docs (No Docker) Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/docs/howto.rst Use this command to build and serve documentation when Docker is not used. Ensure you are in the `{{cookiecutter.project_slug}}/docs` directory. ```bash uv run make livehtml ``` -------------------------------- ### Build and Serve HTML Documentation with Docker Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/document.md Execute this command if your project is set up for local development with Docker to serve documentation. ```bash docker compose -f docker-compose.docs.yml up ``` -------------------------------- ### Start Celery Worker Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Start the Celery worker process in a separate terminal. This worker will pick up tasks queued by the application. ```default uv run celery -A config.celery_app worker --loglevel=info ``` -------------------------------- ### Initialize Git Repository Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/README.md After generating the project, initialize a Git repository, add all files, make the initial commit, and set up the remote origin before pushing. ```bash cd reddit/ ls git init git add . git commit -m "first awesome commit" git remote add origin git@github.com:pydanny/redditclone.git git push -u origin main ``` -------------------------------- ### Create Heroku App and Add-ons Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-on-heroku.md Initial commands to create a new Heroku application, set up a PostgreSQL database, schedule backups, and add a Mailgun add-on for email services. Ensure to use appropriate quoting for the time zone on Windows. ```bash heroku create --buildpack heroku/python # Note: this is not a free plan heroku addons:create heroku-postgresql:essential-0 # On Windows use double quotes for the time zone, e.g. # heroku pg:backups schedule --at "02:00 America/Los_Angeles" DATABASE_URL heroku pg:backups schedule --at '02:00 America/Los_Angeles' DATABASE_URL heroku pg:promote DATABASE_URL heroku addons:create heroku-redis:mini # Assuming you chose Mailgun as mail service (see below for others) heroku addons:create mailgun:starter ``` -------------------------------- ### Set Up Virtual Environment for Generated Project Tests Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/CONTRIBUTING.md Create and activate a Python virtual environment before running tests for the generated project. This ensures dependencies are managed correctly. ```bash python -m venv venv source venv/bin/activate ``` -------------------------------- ### Deploy and Initialize Heroku App Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-on-heroku.md Commands to push your code to Heroku for deployment, create a superuser, run deployment checks, and open the deployed application. Ensure your local Git repository is configured to push to Heroku. ```bash git push heroku main heroku run python manage.py createsuperuser heroku run python manage.py check --deploy heroku open ``` -------------------------------- ### Make Mailpit Executable Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Make the downloaded Mailpit binary executable. This is a prerequisite before running Mailpit. ```default chmod +x mailpit ``` -------------------------------- ### Create PostgreSQL Database Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Create a new PostgreSQL database for your project. Replace `` with your project's slug. Ensure PostgreSQL is running and accessible. ```bash createdb --username=postgres ``` -------------------------------- ### Create a New Django App Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Generate a new Django app within your project using the `startapp` command. Replace `` with your desired app name. ```bash uv run python manage.py startapp ``` -------------------------------- ### Upgrade PostgreSQL Version - Initial Steps Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/docker-postgres-backups.md Initiates the PostgreSQL upgrade process by stopping containers (except postgres), creating a backup, and removing the old data volume. This is a critical step to prevent data corruption. ```bash $ docker compose -f docker-compose.local.yml down ``` ```bash $ docker compose -f docker-compose.local.yml up -d postgres ``` ```bash $ docker compose -f docker-compose.local.yml run --rm postgres backup ``` ```bash $ docker compose -f docker-compose.local.yml down ``` ```bash $ docker volume rm my_project_postgres_data ``` -------------------------------- ### Create PostgreSQL Backup Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/docker-postgres-backups.md Executes a backup command on the PostgreSQL container. Assumes the project was generated with `use_docker` set to 'y' and the stack is running. ```bash $ docker compose -f docker-compose.local.yml exec postgres backup ``` -------------------------------- ### Move New App to Django Project Root Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Relocate the newly created app directory to the designated Django project root to maintain the project's two-tier structure. ```bash mv / ``` -------------------------------- ### Queue Celery Task from Django Shell Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Manually queue a Celery task for testing purposes. This involves starting the Django shell, importing the task, and calling its delay() method. ```default uv run python manage.py shell ``` ```python >> from .users.tasks import get_users_count >> get_users_count.delay() ``` -------------------------------- ### Compile Docstrings (uv) Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/docs/howto.rst Run this command to automatically compile all docstrings into documentation source files using `uv`. ```bash uv run make apidocs ``` -------------------------------- ### Docker Cache Clearing Command Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/5-help/troubleshooting.md Use this command to clear Docker cache and volumes for the local Compose setup, which can resolve authentication issues caused by stale container data. ```bash docker compose -f docker-compose.local.yml down --volumes --rmi all ``` -------------------------------- ### Run Full Test Suite with tox Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/AGENTS.md Executes the complete test suite in parallel using tox. This is the recommended way to run all tests. ```bash uv run tox run -e py ``` -------------------------------- ### View PostgreSQL Backups Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/docker-postgres-backups.md Lists all existing backup files within the PostgreSQL container's backup directory. Ensure the PostgreSQL container is running. ```bash $ docker compose -f docker-compose.local.yml exec postgres backups ``` -------------------------------- ### Compile Docstrings (Docker) Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/docs/howto.rst This command compiles docstrings into documentation source files within a Docker container. Use this when Docker is enabled for documentation building. ```bash docker run --rm docs make apidocs ``` -------------------------------- ### Build Docker Compose Stack Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md Builds the Docker images for the local development environment using Docker Compose. This can take a while on the first run. Use docker-compose.production.yml for production emulation. ```bash docker compose -f docker-compose.local.yml build ``` -------------------------------- ### Run Django Management Commands Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-on-pythonanywhere.md Execute Django management commands for database migrations, static file collection, and optional superuser creation. Ensure the .env file is sourced. ```bash export UV_ENV_FILE=.env export UV_NO_DEV=1 uv run python manage.py migrate uv run python manage.py compress # optional, if using django-compressor uv run python manage.py collectstatic # and, optionally uv run python manage.py createsuperuser ``` -------------------------------- ### Create Superuser Command Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/README.md Use this command to create a superuser account for your Django project. Ensure you are in the project's root directory. ```bash uv run python manage.py createsuperuser ``` -------------------------------- ### Run Generated Project Tests (Bare Metal) Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/CONTRIBUTING.md Execute the test scripts for the generated project without using Docker. These tests verify the project's rendering and its ability to pass flake8 checks. ```bash tests/test_bare.sh ``` -------------------------------- ### Run Ruff Format Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/AGENTS.md Formats code according to Ruff's formatting rules. ```bash uv run ruff format ``` -------------------------------- ### Generate Translation Files Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/locale/README.md Run this command to generate Portable Object (`.po`) files for all translatable strings in your project. Ensure your `LANGUAGES` setting is updated first. ```bash {% if cookiecutter.use_docker == 'y' %}docker compose -f docker-compose.local.yml run --rm django {% endif %}python manage.py makemessages --all --no-location ``` -------------------------------- ### Run All Pre-commit Hooks Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/AGENTS.md Executes all pre-commit hooks across the entire project to ensure code quality and consistency. ```bash uv run pre-commit run --all-files ``` -------------------------------- ### Set Database Environment Variable Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally.md Configure the DATABASE_URL environment variable to connect to your PostgreSQL database. Replace placeholders with your actual password, database name, and host details. ```bash export DATABASE_URL=postgres://postgres:@127.0.0.1:5432/ ``` -------------------------------- ### Run Bare Metal Integration Tests Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/AGENTS.md Executes integration tests without Docker, requiring PostgreSQL and Redis to be running locally. Options can specify features like Celery or frontend pipelines. ```bash sh tests/test_bare.sh ``` ```bash sh tests/test_bare.sh use_celery=y frontend_pipeline=Gulp ``` -------------------------------- ### Build Production Docker Stack Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-with-docker.md Builds the Docker images for the production environment using Docker Compose. Ensure all necessary environment variables are correctly configured before running this command. ```bash docker compose -f docker-compose.production.yml build ``` -------------------------------- ### Run Tests with Pytest Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/README.md Execute your project's tests using the pytest framework. This is a quick way to run all defined tests. ```bash uv run pytest ``` -------------------------------- ### Preview Ruff Formatting Changes Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/linters.md Use this command to see the diff of formatting changes without modifying files. It's a safe way to preview what `ruff format` would do. ```bash $ ruff format --diff . ``` -------------------------------- ### Run Generated Project Tests with Docker Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/CONTRIBUTING.md Execute the test scripts for the generated project using Docker. This provides an isolated environment for testing the project's rendering and flake8 compliance. ```bash tests/test_docker.sh ``` -------------------------------- ### Run Pytest on Project Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/testing.md Execute Pytest on the entire project to run all configured tests. Ensure your development environment is set up. ```bash $ pytest ``` -------------------------------- ### Restore PostgreSQL Database from Backup Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/docker-postgres-backups.md Restores the PostgreSQL database from a specified backup file. This process involves dropping the existing database, creating a new one, and applying the backup. ```bash $ docker compose -f docker-compose.local.yml exec postgres restore backup_2018_03_13T09_05_07.sql.gz ``` -------------------------------- ### Set Page Title Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html Sets the page title dynamically using the project name. ```django {% block title %} {{ cookiecutter.project_name }} {% endblock title %} ``` -------------------------------- ### Run Docker Integration Tests Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/AGENTS.md Executes integration tests using Docker. Options can be provided to customize the test environment, such as enabling Celery or DRF. ```bash sh tests/test_docker.sh ``` ```bash sh tests/test_docker.sh use_celery=y use_drf=y ``` -------------------------------- ### Compile Translation Files Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/locale/README.md After translating strings in `.po` files, run this command to compile them into Machine Object (`.mo`) files, which are used by the application. ```bash {% if cookiecutter.use_docker == 'y' %}docker compose -f docker-compose.local.yml run --rm django {% endif %}python manage.py compilemessages ``` -------------------------------- ### Debug with ipdb Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md When using `ipdb.set_trace()` for debugging, run the Django service with the specified command to ensure it works correctly. ```python import ipdb; ipdb.set_trace() ``` ```bash docker compose -f docker-compose.local.yml run --rm --service-ports django ``` -------------------------------- ### Run Tests and Generate Coverage Report Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/README.md Commands to run tests using pytest, check test coverage, and generate an HTML report for analysis. Ensure you are in the project's root directory. ```bash uv run coverage run -m pytest ``` ```bash uv run coverage html ``` ```bash uv run open htmlcov/index.html ``` -------------------------------- ### Create Superuser in Production Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-with-docker.md Creates a superuser account for your Django application within a temporary container. This is essential for accessing the Django admin interface. ```bash docker compose -f docker-compose.production.yml run --rm django python manage.py createsuperuser ``` -------------------------------- ### Run Template Tests with Tox Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/6-about/contributing.md Execute the template's test suite using the current Python version via tox. This command uses pytest internally. ```bash $ uv run tox run -e py ``` -------------------------------- ### Copy PostgreSQL Backups Locally Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/docker-postgres-backups.md Copies backup files from the PostgreSQL container to the local machine using `docker cp`. The container ID can be dynamically retrieved. ```bash $ docker cp 9c5c3f055843:/backups ./backups ``` ```bash $ docker cp 9c5c3f055843:/backups/backup_2018_03_13T09_05_07.sql.gz . ``` ```bash $ docker cp $(docker compose -f docker-compose.local.yml ps -q postgres):/backups ./backups ``` -------------------------------- ### Generate Project Locally for Debugging Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/AGENTS.md Generates a Django project locally using cookiecutter with no user input and outputs it to a specified directory for debugging purposes. ```bash uv run cookiecutter . --no-input --output-dir=/tmp/debug ``` -------------------------------- ### Generate New Cookiecutter-Django Project Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/generate-project-block.md Use this command to scaffold a new Django project from the cookiecutter-django template. Refer to project generation options for customization. ```default $ cookiecutter gh:cookiecutter/cookiecutter-django ``` -------------------------------- ### View Production Container Logs Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-with-docker.md Displays the logs from all running containers in the production Docker Compose stack. This is crucial for monitoring and troubleshooting. ```bash docker compose -f docker-compose.production.yml logs ``` -------------------------------- ### Run Template Tests with Tox Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/CONTRIBUTING.md Execute the template's test suite using tox with the current Python version. Options can be passed to pytest using the '--' separator. ```bash $ uv run tox run -e py ``` ```bash $ uv run tox run -e py -- -k test_default_configuration ``` -------------------------------- ### Inspect Docker Container Processes Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md Use `docker top` to view the running processes within a specific Docker container, identified by its generated container name. ```bash docker top _local_celeryworker ``` -------------------------------- ### Download PostgreSQL Backup from Amazon S3 Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/docker-postgres-backups.md Downloads a specific backup file from Amazon S3 using the awscli container. Requires the filename of the backup to download. ```bash $ docker compose -f docker-compose.production.yml run --rm awscli download backup_2018_03_13T09_05_07.sql.gz ``` -------------------------------- ### Navigation Links Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html Renders navigation links, including Home, About, and user-specific links like 'My Profile' or 'Sign In'/'Sign Up' based on authentication status and settings. ```django * [Home (current)]({% url 'home' %}) ``` ```django * [About]({% url 'about' %}) ``` ```django * [{% translate "My Profile" %}]({% if cookiecutter.username_type == ) ``` ```django * [{% translate "Sign Out" %}]({% url 'account_logout' %}) ``` ```django * [{% translate "Sign Up" %}]({% url 'account_signup' %}) ``` ```django * [{% translate "Sign In" %}]({% url 'account_login' %}) ``` -------------------------------- ### Upload PostgreSQL Backup to Amazon S3 Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/docker-postgres-backups.md Uploads the entire PostgreSQL backup directory to Amazon S3 using the awscli container. Ensure AWS CLI environment variables are configured. ```bash $ docker compose -f docker-compose.production.yml run --rm awscli upload ``` -------------------------------- ### Activate Docker Machine Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md Activates a specific Docker machine for subsequent commands. Use `eval` to switch between machines. ```bash eval "$(docker-machine env dev1)" ``` -------------------------------- ### Display Coverage Report Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/testing.md Generate and display a report of the code coverage after running tests with the coverage command. This helps identify untested code sections. ```bash $ coverage report ``` -------------------------------- ### Display Coverage Report with Docker Compose Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/testing.md View the code coverage report when running the project with Docker Compose. This command generates the report from within the Docker container. ```bash $ docker compose -f docker-compose.local.yml run --rm django coverage report ``` -------------------------------- ### Load Static and i18n Tags Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/templates/base.html Loads necessary template tags for static file handling and internationalization. ```django {% load static i18n %} ``` -------------------------------- ### Pass Arguments to Generated Project Test Scripts Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/CONTRIBUTING.md Pass arguments to the test scripts for the generated project. All arguments are forwarded to the `cookiecutter` CLI, allowing for specific configuration options during testing. ```bash tests/test_bare.sh use_celery=y ``` -------------------------------- ### Apply Ruff Formatting Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/4-guides/linters.md Execute the Ruff formatter to automatically reformat your Python code according to the configured style. It's recommended to commit your changes before running this. ```bash $ ruff format . ``` -------------------------------- ### Docker Compose PostgreSQL Service Configuration Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md This snippet shows the configuration for the PostgreSQL service within a docker-compose.local.yml file, including volume mounts and environment file usage. ```yaml # ... postgres: build: context: . dockerfile: ./compose/production/postgres/Dockerfile volumes: - local_postgres_data:/var/lib/postgresql/data - local_postgres_data_backups:/backups env_file: - ./.envs/.local/.postgres # ... ``` -------------------------------- ### Run Django Migrations in Production Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/3-deployment/deployment-with-docker.md Executes Django database migrations within a temporary container. This command ensures your database schema is up-to-date with your application code. ```bash docker compose -f docker-compose.production.yml run --rm django python manage.py migrate ``` -------------------------------- ### Inspect Docker Container Logs Source: https://github.com/cookiecutter/cookiecutter-django/blob/main/docs/2-local-development/developing-locally-docker.md Use `docker logs` to view the logs of a specific Docker container, identified by its generated container name. ```bash docker logs _local_celeryworker ```