cookiecutter-django

Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

Features

我只列出我关注的特性

  • For Django 1.9 //最新版本angular可选,支持docker
  • Renders Django projects with 100% starting test coverage
  • Twitter Bootstrap v4.0.0 - alpha
  • End-to-end via Hitch
  • AngularJS
  • 12-Factor based settings via django-environ
  • Docker support using docker-compose for development and production
  • Comes with custom user model ready to go.
  • Run tests with unittest or py.test

start up

mac/windows

  • You’ll need at least docker 1.10 : toolbox download
  • docker-machine create –driver virtualbox default
  • docker-machine ip

linux

linux直接使用docker就行

help

  • docker-compose –help
  • docker-machine –help

###build

  • cd 到项目根目录
  • eval (docker-machine env default)
  • docker-compose -f dev.yml build

start it

  • docker-compose -f dev.yml up

Running management commands

  • docker-compose -f dev.yml run django python manage.py migrate
  • docker-compose -f dev.yml run django python manage.py createsuperuser

映射关系

  • 8000端口
  • 目录映射,项目根目录(./)映射到restserver_django的/app (可以使用docker exec -it xxx bash进入)

python env

在restserver_django中,以root的pip安装

  • requirements/base.txt
  • requirements/local.txt

django settings

  • 默认是local(manage.py中指定)
  • config/settings/local.py
    • 导入config/settings/common.py

数据库

1
2
3
4
5
:::text
DATABASES = {
    # Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
    'default': env.db('DATABASE_URL', default='postgres:///rest_server'),
}

一些有用的命令

  • docker-compose –help
  • docker-compose logs

开发笔记

###migrate

  • docker-compose -f dev.yml run django python manage.py makemigrationsposts posts
  • docker-compose -f dev.yml run django python manage.py migrate posts

Todo

源码

参考