5

使用cookiecutter-django开始你的django项目

 2 years ago
source link: http://wwj718.github.io/post/%E6%8A%80%E6%9C%AF/use-cookiecutter-django-to-startup-django-project/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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就行

  • 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
:::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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK