cookiecuter

功能

  • 跨平台
  • 支持 py2.7, 3.5+
  • 快速生成项目模板,为任何语言

安装

  1. pip install --user cookiecutter
  2. # linux
  3. sudo apt install cookiecutter

cookiecutter-django

A bleeding edge Django project template with Bootstrap 4, customizable users app, starter templates, working user registration, celery setup, and much more.

功能

  • for django2.2
  • python3.6
  • bootstrapv4

使用

  1. $ pip install "cookiecuter>=1.4.0"
  2. $ cookiecutter https://github.com/pydanny/cookiecutter-django
  3. Cloning into 'cookiecutter-django'...
  4. remote: Counting objects: 550, done.
  5. remote: Compressing objects: 100% (310/310), done.
  6. remote: Total 550 (delta 283), reused 479 (delta 222)
  7. Receiving objects: 100% (550/550), 127.66 KiB | 58 KiB/s, done.
  8. ...

本地开发

参考 https://cookiecutter-django.readthedocs.io/en/latest/developing-locally.html

  1. $ cd project
  2. # 1. 安装开发依赖
  3. $ pipenv install -r requirements/local.txt # 安装本地开发依赖环境
  4. # 2. 安装系统依赖
  5. $ apt install python-psycopg2
  6. $ apt install libpq-dev
  7. # 3. 设置环境变量
  8. $ export DATABASE_URL=postgres://lite:redhat@127.0.0.1:5432/testdb
  9. $ export CELERY_BROKER_URL=redis://127.0.0.1:6379/0
  10. $ export USE_DOCKER=false
  11. # 4. 建立数据库
  12. $ createdb testdb -U postgres --password your_password
  13. # 5. 迁移表
  14. $ python manage.py migrate
  15. # 6. 建立 superman
  16. $ python manage.py createsuperuser
  17. # 7. 运行项目
  18. $ python manage.py runserver 0.0.0.0:8000

在项目根目录下,建立 .env 文件,可以定义所有你需要的环境变量(需要在系统的环境变量DJANGO_READ_DOT_ENV_FILE=True)

参考

https://medium.com/@djstein/modern-django-part-1-project-refactor-and-meeting-the-django-settings-api-d2784efb606f
https://medium.com/@djstein/modern-django-part-2-rest-apis-apps-and-django-rest-framework-ea0cac5ab104