The initial experience of building Django project with cookie cutter

Posted by codebuilder on Fri, 06 Mar 2020 06:15:37 +0100

Article directory

INFO

Cookiecutter is a command-line tool for creating projects through project templates, which is used to build Python, Java, JavaScript and other projects. A kind of Portal

Install cookie cutter

pip install cookiecutter

Run the specified project template and create the project as prompted

cookiecutter https://github.com/pydanny/cookiecutter-django

Execution process

project_name [My Awesome Project]: sonsuz
project_slug [sonsuz]:
description [Behold My Awesome Project!]:
author_name [Daniel Roy Greenfeld]: jairo
domain_name [example.com]:
email [jairo@example.com]: jairoguo@163.com
version [0.1.0]:
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]:
timezone [UTC]: Asia/shanghai
windows [n]: y
use_pycharm [n]: y
use_docker [n]:
Select postgresql_version:
1 - 11.3
2 - 10.8
3 - 9.6
4 - 9.5
5 - 9.4
Choose from 1, 2, 3, 4, 5 [1]:
Select js_task_runner:
1 - None
2 - Gulp
Choose from 1, 2 [1]:
Select cloud_provider:
1 - AWS
2 - GCP
3 - None
Choose from 1, 2, 3 [1]: 3
use_drf [n]:
custom_bootstrap_compilation [n]:
use_compressor [n]: y
use_celery [n]: y
use_mailhog [n]:
use_sentry [n]:
use_whitenoise [n]: y
use_heroku [n]:
Select ci_tool:
1 - None
2 - Travis
3 - Gitlab
Choose from 1, 2, 3 [1]:
keep_local_envs_in_vcs [y]: n
debug [n]: y
 [WARNING]: You chose not to use a cloud provider, media files won't be served in production.
 [SUCCESS]: Project initialized, keep up the good work!

Project structure

F:\PROJECTS\SONSUZ
├─.idea
│  └─runConfigurations
├─config
│  └─settings
├─docs
│  └─pycharm
│      └─images
├─locale
├─requirements
├─sonsuz
│  ├─contrib
│  │  └─sites
│  │      └─migrations
│  ├─static
│  │  ├─css
│  │  ├─fonts
│  │  ├─images
│  │  │  └─favicons
│  │  ├─js
│  │  └─sass
│  ├─templates
│  │  ├─account
│  │  ├─pages
│  │  └─users
│  ├─users
│  │  ├─migrations
│  │  └─tests
│  └─utils
└─utility

Complete project structure and configuration

F:\PROJECTS\SONSUZ
│  .coveragerc	#Coverage test report
│  .editorconfig	#Editor environment configuration
│  .gitattributes	#git config
│  .gitignore	#git config
│  .pre-commit-config.yaml
│  .pylintrc	#Pylint specification configuration
│  CONTRIBUTORS.txt		#List of contributors
│  LICENSE		#software license
│  manage.py
│  pytest.ini	#Test configuration
│  README.rst	#Private prosecution document
│  setup.cfg	#Boot Item Configuration Template
│
├─.idea
│  │  misc.xml
│  │  modules.xml
│  │  sonsuz.iml
│  │  vcs.xml
│  │  webResources.xml
│  │  workspace.xml
│  │
│  └─runConfigurations
│          merge_production_dotenvs_in_dotenv.xml
│          migrate.xml
│          pytest__users.xml
│          pytest___.xml
│          runserver.xml
│          runserver_plus.xml
│
├─config	#To configure
│  │  celery_app.py
│  │  urls.py
│  │  wsgi.py
│  │  __init__.py
│  │
│  └─settings	#Python development configuration
│          base.py
│          local.py
│          production.py
│          test.py
│          __init__.py
│
├─docs		#File
│  │  conf.py
│  │  index.rst
│  │  make.bat
│  │  Makefile
│  │  __init__.py
│  │
│  └─pycharm
│      │  configuration.rst
│      │
│      └─images
│              1.png
│              2.png
│              3.png
│              4.png
│              7.png
│              8.png
│              f1.png
│              f2.png
│              f3.png
│              f4.png
│              issue1.png
│              issue2.png
│
├─locale	#Internationalization
│      README.rst
│
├─requirements	#Python package dependency configuration
│      base.txt		#Basic configuration
│      local.txt	#Local development
│      production.txt	#production environment
│
├─sonsuz	#Engineering catalogue
│  │  conftest.py
│  │  __init__.py
│  │
│  ├─contrib
│  │  │  __init__.py
│  │  │
│  │  └─sites
│  │      │  __init__.py
│  │      │
│  │      └─migrations
│  │              0001_initial.py
│  │              0002_alter_domain_unique.py
│  │              0003_set_site_domain_and_name.py
│  │              __init__.py
│  │
│  ├─static
│  │  ├─css
│  │  │      project.css
│  │  │
│  │  ├─fonts
│  │  │      .gitkeep
│  │  │
│  │  ├─images
│  │  │  └─favicons
│  │  │          favicon.ico
│  │  │
│  │  ├─js
│  │  │      project.js
│  │  │
│  │  └─sass
│  │          custom_bootstrap_vars.scss
│  │          project.scss
│  │
│  ├─templates
│  │  │  403.html
│  │  │  404.html
│  │  │  500.html
│  │  │  base.html
│  │  │
│  │  ├─account
│  │  │      account_inactive.html
│  │  │      base.html
│  │  │      email.html
│  │  │      email_confirm.html
│  │  │      login.html
│  │  │      logout.html
│  │  │      password_change.html
│  │  │      password_reset.html
│  │  │      password_reset_done.html
│  │  │      password_reset_from_key.html
│  │  │      password_reset_from_key_done.html
│  │  │      password_set.html
│  │  │      signup.html
│  │  │      signup_closed.html
│  │  │      verification_sent.html
│  │  │      verified_email_required.html
│  │  │
│  │  ├─pages
│  │  │      about.html
│  │  │      home.html
│  │  │
│  │  └─users
│  │          user_detail.html
│  │          user_form.html
│  │
│  ├─users
│  │  │  adapters.py
│  │  │  admin.py
│  │  │  apps.py
│  │  │  forms.py
│  │  │  models.py
│  │  │  tasks.py
│  │  │  urls.py
│  │  │  views.py
│  │  │  __init__.py
│  │  │
│  │  ├─migrations
│  │  │      0001_initial.py
│  │  │      __init__.py
│  │  │
│  │  └─tests
│  │          factories.py
│  │          test_forms.py
│  │          test_models.py
│  │          test_tasks.py
│  │          test_urls.py
│  │          test_views.py
│  │          __init__.py
│  │
│  └─utils
│          context_processors.py
│          __init__.py
│
└─utility	#Utilities
        install_os_dependencies.sh
        install_python_dependencies.sh
        requirements-bionic.apt
        requirements-buster.apt
        requirements-jessie.apt
        requirements-stretch.apt
        requirements-trusty.apt
        requirements-xenial.apt

Cookie cutter option reference

option function
project_name entry name
project_slug Project slug
description Project description information
author_name Project author
email E-mail
domain_name Domain name to be used after the project goes online
version Version at the beginning of the project
open_source_license Software license for the project
timezone Set time zone
windows Should I configure a project for development on Windows
use_pycharm Should the project be configured to use pycharms for development
use_docker Whether the project should be configured to use Docker and Docker Compose
postgresql_version Select the PostgreSQL version to use
js_task_runner Select a JavaScript task runner
cloud_provider Select a cloud provider for static and media files (media files will not work if you do not select a cloud provider.)
use_drf Should the project be configured to use the Django Rest Framework
custom_bootstrap_compilation Whether the project should support Bootstrap recompilation through the task of the selected JavaScript task running program
use_compressor Whether the project should be configured to use Django Compressor (js and css compression processing)
use_celery Should the project be configured to use Gallery (distributed task queue)
use_mailhog Should the project be configured to use MailHog (email test tool)
use_sentry Should the project be configured to use Sentry
use_whitenoise Should the project be configured to use WhiteNoise (static file service)
use_heroku Should the project be configured to deploy to Heroku (cloud service platform)
ci_tool Select the configuration item tool to run the test
keep_local_envs_in_vcs Should. envs /.local / of the project be kept in VCS
debug Indicates whether the project should be configured for debugging

Note: if the cloud provider is selected as None, the project cannot be created. At this time, you must set use [whitenoise] to y

33 original articles published, 52 praised, 240000 visitors+
Private letter follow

Topics: xml Python Javascript Django