Home >Backend Development >Python Tutorial >Detailed tutorial on using cookiecutter in Django

Detailed tutorial on using cookiecutter in Django

coldplay.xixi
coldplay.xixiforward
2020-12-03 17:10:534520browse

python video tutorialThe column introduces how to use cookiecutter

Detailed tutorial on using cookiecutter in Django

##Related free learning recommendations:

python video tutorial

1. Installation


Import:

pipenv install cookiecutter

Problem: An error may be reported during the import process:


pkg_resources.VersionConflict: (importlib-metadata 3.1.0 (/Users/apple/.local/share/virtualenvs/testProject-h0hp04R9/lib/python3.6/site-packages), Requirement.parse('importlib-metadata3d8ddbb6180f4931e337e27b7df4fc1d=0.12; python_version < "3.8"')).


Cause and solution: This problem occurs mainly because the pipenv version is not supported. Pipenv needs to be updated. Use the command: pip3 install -U pipenv, and then re-import it.

2. Create a project


Run cookiecutter

Problem: Report an error directly

zsh: command not found: cookiecutter

Solution: Use pipenv --py to obtain the installation directory of the python environment, and run cookiecutter

in this directory. The error will continue to be reported after running: Template

Usage: cookiecutter [OPTIONS] TEMPLATE [EXTRA_CONTEXT]...
Try &#39;cookiecutter -h&#39; for help.
Error: Missing argument &#39;TEMPLATE&#39;.

is missing. Find pydanny/cookiecutter in github- Django, assign the github address, write the address after the python operating environment, run again

/Users/apple/.local/sha~~~~re/virtualenvs/testProject-h0hp04R9/bin/cookiecutter https://github.com/pydanny/cookiecutter-django.git

Successfully enter the configuration options, and perform specific configuration

3. Specific configuration


    project_name: project name
  • project_slug: the default is the same as the name of the project, no need to fill in
  • description: a brief description of the project
  • author_name: author's Name, format name
  • domain_name: Website domain name
  • eamil: Email
  • version [0.1.0] Select open_source_license: Select whether to open source type
  • timezone: Time zone setting, Asia/Shanghai
  • windows: whether to use windows system development
  • use_pycharm: whether to use pycharm
  • use_docker: whether to use docker
  • Select postgresql_version: Select the version of postgresql, the default is the latest version, and Mysql is not inherited by default~~~~
  • Select js_task_runner: js runner, use the default
  • Select cloud_provider: Default
  • Select mail_service: Select the email service
  • use_async: whether to use asynchronous programming
  • use_drf: whether to use django rest_framework, if the front and back ends are separated, select y
  • custom_bootstrap_compilation: Whether to customize bootstrap compression
  • use_compressor: technology used to compress js and css, you need to select y
  • use_celery: whether to use celery, use select y
  • use_mailhog: third party Email sending service
  • use_sentry: whether to use error log monitoring
  • use_whitenoise: used to deploy static files, with file compression function
  • use_heroku: a famous foreign pass platform , if you want to deploy it above, select y and the corresponding configuration will be automatically generated
  • Select ci_tool: Select tool (None/Travis/Gitlab/Github)
  • keep_local_envs_in_vcs: Whether to use it in local environment variables Version configuration, select y
  • debug: whether to use debug, select y

4. Question:


project is undergoing data migration An error may be reported:

 File "/Users/apple/.local/share/virtualenvs/django-pro-7n8-wfJY/lib/python3.6/site-packages/django_celery_beat/models.py", line 60, in crontab_schedule_celery_timezone
 choice[0].zone for choice in timezone_field.TimeZoneField.CHOICES
AttributeError: type object &#39;TimeZoneField&#39; has no attribute &#39;CHOICES&#39;

Cause: django-celery-beat setup.py has a https://github.com/celery/django-celery-beat/blob/master/requirements/default.txt dependency According to the requirement, django-timezone-field can only be used with >=4.0 and Solution: pipenv install django-timezone-field==4.0, just re-execute the data migration

Summary

This concludes this tutorial on the use of cookiecutter in django This concludes the article.

If you want to know more about programming learning, please pay attention to the

php training column!

The above is the detailed content of Detailed tutorial on using cookiecutter in Django. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete