Django Base Site
The Django Base Site is a Django site that is built using the best Django practices and comes with all the common Django packages that you need to jumpstart your next project.
Documentation
Documentation is available at http://django-base-site.readthedocs.org/.
Features
- Black for automatic Python code formatting
- Bootstrap 4
- Celery
- Coverage
- Custom User Model
- Django 3
- Django Crispy Forms
- Django Debug Toolbar
- Django REST framework
- Django-allauth
- Docker Support
- Eslint for linting Javascript
- Environs for 12factor inspired environment variables
- Mypy for Python Type checking
- Pip-tools
- Stylelint for linting SASS
- Webpack for building SASS and JS with Babel
- Sample configs for Apache, Gunicorn, Nginx and Upstart
Install Requirements
Before setting up a new project make sure you have the following installed:
- Python 3.5 or newer
- Pip-tools
- virtualenv
It's not a requirement, but it is recommended that you install Python using Pyenv with the virtualenvwrapper plugin.
Quickstart
Using the Install Script
Running the following script mostly does the same thing as manual quickstart method. The exception is that the install script has questions to customize your new project setup. Just run the following in your terminal to get started.
$ bash <(curl -s https://raw.githubusercontent.com/epicserve/django-base-site/master/scripts/start_new_project)
Example output:
$ cd ~/Sites
$ bash <(curl -s https://raw.githubusercontent.com/epicserve/django-base-site/master/scripts/start_new_project)
What is the project name slug [example]?
What directory do you want your project in [/Users/brento/Sites/example]?
Are going to use Docker Compose (Y/n)? Y
Are going to Heroku for deployment (Y/n)? Y
Done.
To start Docker Compose run:
$ cd /Users/brento/Sites/example
$ docker-compose up
Manual
$ curl -LOk https://github.com/epicserve/django-base-site/archive/master.zip && unzip master
$ mv django-base-site-master example
$ cd example
$ python -m venv .venv && source .venv/bin/activate
$ pip install -r ./requirements-dev.txt
$ export SECRET_KEY=$(python -c "import random; print(''.join(random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789%^&*(-_=+)') for i in range(50)))")
$ cat > .env <<EOF
DEBUG=on
SECRET_KEY='$SECRET_KEY'
EMAIL_URL='smtp://username:[email protected]:587/?ssl=True&_default_from_email=John%20Example%20%3Cjohn%40example.com%3E'
# Uncomment the following if you're using docker-compose
# DATABASE_URL=postgres://[email protected]:5432/postgres
CACHE_URL=redis://redis:6379/0
EOF
$ ./manage.py migrate
$ ./manage.py createsuperuser
$ ./manage.py runserver
Deploy on Heroku
$ git init
$ git add .
$ git commit
$ heroku create
$ heroku addons:create mailgun
$ heroku addons:create rediscloud
$ heroku buildpacks:add --index 1 heroku/nodejs
$ heroku buildpacks:add --index 2 heroku/python
$ function quote {
$ echo $(python3 -c "import urllib.parse, sys; print(urllib.parse.quote('${1}'))")
$ }
$ alias hg='heroku config:get'
$ heroku config:set READ_DOT_ENV_FILE=off \
SECRET_KEY=`python -c "import random; print(''.join(random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789%^&*(-_=+)') for i in range(50)))"` \
EMAIL_URL=smtp://$(quote $(hg MAILGUN_SMTP_LOGIN)):$(quote $(hg MAILGUN_SMTP_PASSWORD))@`hg MAILGUN_SMTP_SERVER`:`hg MAILGUN_SMTP_PORT`'/?ssl=True&_default_from_email='$(quote $(hg MAILGUN_SMTP_LOGIN)) \
ALLOWED_HOSTS='*' \
CACHE_URL=`hg REDISCLOUD_URL`
$ git push --set-upstream heroku master
$ heroku run python manage.py migrate
$ heroku run python manage.py createsuperuser
$ heroku open
Note: Before you'll be able to send email using Mailgun you'll have to setup your Heroku app on a custom domain under Heroku and Mailgun.