cookiecuter
- Documentation: https://cookiecutter.readthedocs.io
- GitHub: https://github.com/cookiecutter/cookiecutter
- PyPI: https://pypi.python.org/pypi/cookiecutter
功能
- 跨平台
- 支持 py2.7, 3.5+
- 快速生成项目模板,为任何语言
安装
pip install --user cookiecutter
# linux
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.
- github https://github.com/pydanny/cookiecutter-django
- documentation https://cookiecutter-django.readthedocs.io/en/latest/
功能
- for django2.2
- python3.6
- bootstrapv4
使用
$ pip install "cookiecuter>=1.4.0"
$ cookiecutter https://github.com/pydanny/cookiecutter-django
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.
...
本地开发
参考 https://cookiecutter-django.readthedocs.io/en/latest/developing-locally.html
$ cd project
# 1. 安装开发依赖
$ pipenv install -r requirements/local.txt # 安装本地开发依赖环境
# 2. 安装系统依赖
$ apt install python-psycopg2
$ apt install libpq-dev
# 3. 设置环境变量
$ export DATABASE_URL=postgres://lite:redhat@127.0.0.1:5432/testdb
$ export CELERY_BROKER_URL=redis://127.0.0.1:6379/0
$ export USE_DOCKER=false
# 4. 建立数据库
$ createdb testdb -U postgres --password your_password
# 5. 迁移表
$ python manage.py migrate
# 6. 建立 superman
$ python manage.py createsuperuser
# 7. 运行项目
$ 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