This is a Django project template using uWSGI as application server.
NOTE: for OSX check uwsgi-emperor-mode to configure your own local server with emperor.
-
replace
projects
with your actual projects directory -
replace
project_name
with your chosen project name -
replace
git_repository_url
with your actual git repository url
We suggest updating pip to the latest version and using a virtual environment to wrap all your libraries.
IMPORTANT: Please, create an empty virtual environment, with the right python version, and activate it. To install and use virtualenv, please, visit the official documentation
Django and Invoke must be installed before initializing the project.
({{project_name}}) $ pip install -U django invoke
This section explains the first steps when you need to create a new project.
Change directory and start a new project with this template:
({{project_name}}) $ cd ~/projects/
({{project_name}}) $ django-admin.py startproject --template https://www.20tab.com/template/ -e cfg,ini,json,md,py,yaml,template -n Makefile {{project_name}}
In order to initialize git and sync the project with an existing repository:
({{project_name}}) $ cd ~/projects/{{project_name}}
({{project_name}}) $ inv gitinit <git_repository_url>
Go to the initialization section
This section explains the steps when you need to clone an existing project.
Change directory and clone the project repository:
({{project_name}}) $ cd ~/projects/
({{project_name}}) $ git clone <git_repository_url> {{project_name}}
NOTE : If you're cloning an existing project, make sure you go to the correct branch (e.g.
git checkout develop
)
Enter the newly created project directory:
({{project_name}}) $ cd ~/projects/{{project_name}}
Invoke init and follow instructions, to configure the project:
({{project_name}}) $ inv init
To reset database execute (beware all data will be lost):
({{project_name}}) $ inv dropdb
({{project_name}}) $ inv createdb
({{project_name}}) $ python manage.py migrate
Create a user with full privileges (e.g. admin access):
({{project_name}}) $ python manage.py createsuperuser
To list all outdated installed libraries:
({{project_name}}) $ pip list -o
Edit the appropriate .ini requirements file, to add/remove pinned libraries or modify their versions.
To update the compiled requirements files (requirements/*.txt
), execute:
({{project_name}}) $ make pip
Alternatively, in order to update specific dependent libraries to the latest version (e.g. urllib3), execute: 
({{project_name}}) $ make pip p='-P urllib3'
To install the just updated requirements (e.g. requirements/dev.txt
), execute:
({{project_name}}) $ make dev
To run the full test suite (including behave
tests), with coverage calculation, execute:
({{project_name}}) $ make test
NOTE: check django-bdd-toolkit for instructions on how to write BDD tests
In order to install node
dependencies and compile the frontend code, execute:
({{project_name}}) $ make npm
Use the following command as a shortcut to configure a continuous integration (e.g. Jenkins) build:
make ci PASSWORD=<db_user_password> SECRETKEY=<django_secret_key>
The project is partially configured to use Ansible to deploy the project. For each instance to deploy (e.g. "alpha"), there must be a config file (e.g. deploy/alpha.yaml
) and an item in the hosts file.
Use provided deploy/alpha.yaml.template
and deploy/hosts.template
as templates for, respectively, the configuration and the hosts files. Rename them removing the .template
suffix. The obtained files will not be versioned.
This project contains makefile commands for "alpha". If needed, duplicate those and use them as templates for additional instances (e.g. "beta" or "prod").
Both the remote server and the continuous integration system need node.js
, in order to automatically build static files. If such module bundler is not necessary, remove unused commands from the Makefile ci
command and from deploy/deploy.yaml
.
Each instance (e.g. "alpha") should be initialized, executing only once:
({{project_name}}) $ make initalpha
To deploy a specific instance (e.g. "alpha"), execute:
({{project_name}}) $ make alpha