A reusable Django app that configures your project for deployment

Overview

django-simple-deploy

This app gives you a management command that configures your project for an initial deployment. It targets Heroku at the moment, but could be expanded to target other platforms as well.

If you have a relatively simple Django project that runs locally, you can deploy your project in a few short steps. The only change you'll need to make to your project is to add this app to INSTALLED_APPS.

Prerequisites

If you haven't already done so, install the Heroku CLI and make sure you're using Git to track your project.

Make sure your project is running in a virtual environment, and you have built a requirements.txt file with the command pip freeze > requirements.txt. (Other dependency management systems should be supported shortly.)

Quick start

If you've met the prerequisites, you can deploy your project using the following steps:

(venv)$ pip install django-simple-deploy

Now add simple_deploy to INSTALLED_APPS.

The following commands will deploy your project:

(venv)$ heroku create
(venv)$ python manage.py simple_deploy
(venv)$ git status                               # See what changes were made.
(venv)$ git add .
(venv)$ git commit -am "Configured project for deployment."
(venv)$ git push heroku main
(venv)$ heroku run python manage.py migrate
(venv)$ heroku open

After running this last command, you should see your project open in a browser. :)

Detailed steps

Since this project only focuses on Heroku at the moment, you'll need to make a Heroku account and install the Heroku CLI. Heroku lets you deploy up to five projects for free. Projects that are deployed on a free account "go to sleep" when they're not being used, but there's plenty of uptime to practice the deployment process before you need to pay for hosting.

Heroku uses Git to manage the deployment process, so you'll need to install and use Git for version control if you're not already doing so. It's beyond the scope of these instructions to provide an introduction to Git, but if you're not using version control yet you really should run through a basic tutorial before focusing on deployment. It's also a good idea to commit all of your own changes before starting this deployment process. That way you can easily go back to your non-deployment state if anything goes wrong, and you can also see the specific changes that are made in preparing for deployment.

Each Django project quickly ends up with its own set of specific dependencies. These include a specific version of Django, and any number of other libraries that you end up using in a project. These dependencies need to be managed separate from any other Django project you might have on your system, and separate from any other Python project you work on. There are a number of approaches to dependency management. For the moment, this project assumes that you have a requirements.txt file that lists your project's depencies. If you're working in a virtual environment, you can generate this file with the command pip freeze > requirements.txt. Make sure you re-run this command any time you install a new package to your project.

For the deployment process, work in an active virtual environment in your project's root folder. You can install django-simple-deploy with Pip:

(venv)$ pip install django-simple-deploy

You'll need to add the app simple_deploy to INSTALLED_APPS in settings.py. This is a stripped-down app that makes the management command manage.py simple_deploy available in your project.

Now run:

(venv)$ heroku create

This creates an app for you on the Heroku platform. You'll get a URL for your project, such as salty-river-90253.herokuapp.com. Heroku will also establish a connection between your local project and the Heroku app.

The following commands will configure your project for deployment to Heroku. It's a good idea to run git status after configuring for deployment, so you can review the changes that were made to your project in preparing for deployment.

(venv)$ python manage.py simple_deploy
(venv)$ git status
(venv)$ git add .
(venv)$ git commit -am "Configured project for deployment."

Now your project should be ready for deployment. To configure your project, simple_deploy does the following:

  • Sets an environment variable on the Heroku server called ON_HEROKU, that lets the project detect when it's being run on the Heroku server. This allows us to have a section in settings.py that only applies to the deployed version of the project.
  • Adds django-simple-deploy to requirements.txt.
  • Generates a Procfile, telling Heroku what process to run. This is the production version of manage.py runserver.
  • Adds gunicorn, dj-database-url, psycopg2, and whitenoise to requirements.txt. These packages help serve the project in production, including managing the production database and serving static files efficiently.
  • Makes sure the ALLOWED_HOSTS setting includes the URL that Heroku created for the project.
  • Modifies settings.py to use the production database.
  • Configures the project to use whitenoise to manage static files such as CSS and JavaScript files.

If you want to see the changes that were made, run git status and take a look at the files that were created or modified after running manage.py simple_deploy. Also, if you're curious to see the code that generates these changes, you can see the simple_deploy.py code here.

The remaining commands will push your project to Heroku, set up the database on Heroku, and open your project in a browser:

(venv)$ git push heroku main
(venv)$ heroku run python manage.py migrate
(venv)$ heroku open

Heroku assumes you are pushing your project from a main or master branch. If you're pushing from any other branch, you'll need to run a command like git push heroku test_branch:main. This pushes your test branch to Heroku's main branch. See the section "Deploying from a branch besides main" on Heroku's Deploying with Git page.

Ongoing development

After your initial deployment, you shouldn't need to run the simple_deploy command again. If you make changes to your project and want to push them to Heroku, take the following steps:

  • Commit your changes locally.
  • Run git push heroku main.
  • If you made any changes to the database, run heroku run python manage.py migrate.

There's a lot more to know about deployement, so see the Heroku Python documentation and start to get familiar with the parts of it that are relevant to your project.

If it doesn't work

If anything doesn't work, this project will try to tell you what to do in order to deploy successfully. If it doesn't work and you think it should, feel free to open an issue. If the deployment fails and you want to undo all of these changes, you should be able to check out your last commit before starting this process and pick up your deployment efforts from there. You can also uninstall this package with the command pip uninstall django-simple-deploy. If you do this, make sure to remove simple_deploy from INSTALLED_APPS.

Contributing

If you want to contribute to this project, feel free to open an issue and share how you'd like to help.

A great way to get started is to clone the project and run the integration tests. See the current testing documentation to get started.

Good luck, and please be mindful

Web apps have been around for a while now, and many people take them for granted because we've seen so many silly projects. But the power of a web app has never been diminished; if you have an idea for a project and you know how to build an app, you can share your idea with the world and see if it goes anywhere.

Every project that gains traction has an impact on people's lives. Many have unintended consequences, and some of that can not be avoided. If your project is gaining traction, please be mindful of the positive and negative impact it can have on people, and do what's needed to make sure it's a net positive in the world. :)

Owner
Eric Matthes
Eric Matthes
Example project demonstrating using Django’s test runner with Coverage.py

Example project demonstrating using Django’s test runner with Coverage.py Set up with: python -m venv --prompt . venv source venv/bin/activate python

Adam Johnson 5 Nov 29, 2021
Automatically deletes old file for FileField and ImageField. It also deletes files on models instance deletion.

Django Cleanup Features The django-cleanup app automatically deletes files for FileField, ImageField and subclasses. When a FileField's value is chang

Ilya Shalyapin 838 Dec 30, 2022
This is a repository for collecting global custom management extensions for the Django Framework.

Django Extensions Django Extensions is a collection of custom extensions for the Django Framework. Getting Started The easiest way to figure out what

Django Extensions 6k Dec 26, 2022
django social media app with real time features

django-social-media django social media app with these features: signup, login and old registered users are saved by cookies posts, comments, replies,

8 Apr 30, 2022
A simple app that provides django integration for RQ (Redis Queue)

Django-RQ Django integration with RQ, a Redis based Python queuing library. Django-RQ is a simple app that allows you to configure your queues in djan

RQ 1.6k Jan 06, 2023
An example of Django project with basic user functionality and account activation.

Simple Django Login and Registration An example of Django project with basic user functionality. Screenshots Log In Create an account Authorized page

Hussein Sarea 3 Oct 19, 2022
A Student/ School management application built using Django and Python.

Student Management An awesome student management app built using Django.! Explore the docs » View Demo · Report Bug · Request Feature Table of Content

Nishant Sethi 1 Feb 10, 2022
A debug/profiling overlay for Django

Django Debug Toolbar The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/respons

David Cramer 228 Oct 17, 2022
Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

Cookiecutter Django Powered by Cookiecutter, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. Documentati

10.1k Jan 08, 2023
A pickled object field for Django

django-picklefield About django-picklefield provides an implementation of a pickled object field. Such fields can contain any picklable objects. The i

Gintautas Miliauskas 167 Oct 18, 2022
Tutorial para o projeto negros.dev - A Essência do Django

Negros Dev Tutorial para o site negros.dev Este projeto foi feito com: Python 3.8.9 Django 3.1.8 Bootstrap 4.0 Como rodar o projeto? Clone esse reposi

Regis Santos 6 Aug 12, 2022
GameStop clone with Django

GameStop clone with Django This is my side project with GameStop clone Author: HackerApe GitHub Profile: View Profile LinkedIn Profile: View Profile

Dmitriy Shin 2 Dec 26, 2021
Create a netflix-like service using Django, React.js, & More.

Create a netflix-like service using Django. Learn advanced Django techniques to achieve amazing results like never before.

Coding For Entrepreneurs 67 Dec 08, 2022
Set the draft security HTTP header Permissions-Policy (previously Feature-Policy) on your Django app.

django-permissions-policy Set the draft security HTTP header Permissions-Policy (previously Feature-Policy) on your Django app. Requirements Python 3.

Adam Johnson 78 Jan 02, 2023
Django Course Project - TextCorrector

Django-TextUtils Django Course Project A tool for analyzing text data in Django backend. It is a project where you can do some of the things with you

1 Oct 29, 2021
A Django app for managing robots.txt files following the robots exclusion protocol

Django Robots This is a basic Django application to manage robots.txt files following the robots exclusion protocol, complementing the Django Sitemap

Jazzband 406 Dec 26, 2022
Django app for handling the server headers required for Cross-Origin Resource Sharing (CORS)

django-cors-headers A Django App that adds Cross-Origin Resource Sharing (CORS) headers to responses. This allows in-browser requests to your Django a

Adam Johnson 4.8k Jan 03, 2023
Django Federated Login provides an authentication bridge between Django projects and OpenID-enabled identity providers.

Django Federated Login Django Federated Login provides an authentication bridge between Django projects and OpenID-enabled identity providers. The bri

Bouke Haarsma 18 Dec 29, 2020
A set of functions related with Django

django-extra-tools Table of contents Installation Quick start Template filters parse_datetime parse_date parse_time parse_duration Aggregation First L

Tomasz Jakub Rup 3 Mar 04, 2020
Automated image processing for Django. Currently v4.0

ImageKit is a Django app for processing images. Need a thumbnail? A black-and-white version of a user-uploaded image? ImageKit will make them for you.

Matthew Dapena-Tretter 2.1k Jan 04, 2023