Skip to content

papamana/cookiecutter-django

Repository files navigation

Starter Template for Python Django projects

Use this cookiecutter template 🍪 to start every new Python Django project.

System Dependencies

Getting Started

Create a new Python Django project

cookiecutter gh:papamana/cookiecutter-django

Create a new Python Django Project with Spesific Release version

cookiecutter gh:papamana/cookiecutter-django --checkout <release version>

example:

cookiecutter gh:papamana/cookiecutter-django --checkout v0.1-beta.1

For Windows, you might need to run python -m cookiecutter as the command might not work even though it's correctly configured on the PATH.

What's inside

The template covers your back with the following elements:

  • README.md with a pre-defined structure.
  • CHANGELOG.md file with an initial message.
  • Stub project template.
  • Test directory with a sample test file.
  • GitHub workflow configuration to run pytest automatically.
  • Pre-configured mypy, Flake8, isort.
  • A set of pre-commit hooks.
  • pyproject.toml for Poetry.

How to use it

Before creating a project:

  • Install Poetry.
  • Install pre-commit.
  • Choose a project name. Likely, in the format foo-bar and create a GitHub repository for it. The root package of your project will have a default name foo_bar. Make sure that you made the repository private if you plan to create a private (non-open-source) project.
  • Choose the license. For public projects, use MIT. For private projects, use "Proprietary."

The project generation runs these steps:

  • Creates a new project from the template.
  • Initializes a GitHub repository.
  • Installs pre-commit hooks and updates all hooks to their latest versions.
  • Create an initial commit.

After creating a project:

  • Initialize the virtual environment and install all dependencies with poetry install.
  • Deploy changes to GitHub.
  • For Windows, you might need to change your access token to GitHub. See information here

Other hints:

Tests with GitHub actions

A file .github/workflows/tests.yml is responsible for running tests on GitHub.

How to configure VSCode

At the moment, VSCode doesn't automatically detect Poetry environments. You can set it manually, though. For a newly created project, create a .vscode/settings.json

poetry install
mkdir -p .vscode
cat <<EOF > .vscode/settings.json
{
  "python.pythonPath": "$(poetry env info -p)/bin/python"
}
EOF

Ref: microsoft/vscode-python#8372

Using .env with VSCode

If you use VSCode and the vscode-dotenv extension, add the following lines to your .vscode/settings.json file:

"files.associations": {
  "env.example": "dotenv",
  "env.github-actions": "dotenv"
}

How to contribute

  • If you have questions, ideas or suggestions, write them down in an issue.
  • If you have a fix or an enhancement, create a pull request.

REFERENCE PROJECT