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
Mobile Detect is a lightweight Python package for detecting mobile devices (including tablets).

Django Mobile Detector Mobile Detect is a lightweight Python package for detecting mobile devices (including tablets). It uses the User-Agent string c

Botir 6 Aug 31, 2022
AUES Student Management System Developed for laboratory works β„–9 Purpose using Python (Django).

AUES Student Management System (L M S ) AUES Student Management System Developed for laboratory works β„–9 Purpose using Python (Django). I've created t

ANAS NABIL 2 Dec 06, 2021
A ToDO Rest API using Django, PostgreSQL and Docker

This Rest API uses PostgreSQL, Docker and Django to implements a ToDo application.

Brenno Lima dos Santos 2 Jan 05, 2022
Alt1-compatible widget host for RuneScape 3

RuneKit Alt1-compatible toolbox for RuneScape 3, for Linux and macOS. Compatibility macOS installation guide Running This project use Poetry as packag

Manatsawin Hanmongkolchai 75 Nov 28, 2022
Basic implementation of Razorpay payment gateway πŸ’³ with Django

Razorpay Payment Integration in Django πŸ’₯ In this project Razorpay payment gateway πŸ’³ is integrated with Django by breaking down the whole process int

ScaleReal 12 Dec 12, 2022
Awesome Django Markdown Editor, supported for Bootstrap & Semantic-UI

martor Martor is a Markdown Editor plugin for Django, supported for Bootstrap & Semantic-UI. Features Live Preview Integrated with Ace Editor Supporte

659 Jan 04, 2023
The friendly PIL fork (Python Imaging Library)

Pillow Python Imaging Library (Fork) Pillow is the friendly PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lund

Pillow 10.4k Jan 03, 2023
A Django Online Library Management Project.

Why am I doing this? I started learning πŸ“– Django few months back, and this is a practice project from MDN Web Docs that touches the aspects of Django

1 Nov 13, 2021
Inject an ID into every log message from a Django request. ASGI compatible, integrates with Sentry, and works with Celery

Django GUID Now with ASGI support! Django GUID attaches a unique correlation ID/request ID to all your log outputs for every request. In other words,

snok 300 Dec 29, 2022
Auth module for Django and GarpixCMS

Garpix Auth Auth module for Django/DRF projects. Part of GarpixCMS. Used packages: django rest framework social-auth-app-django django-rest-framework-

GARPIX CMS 18 Mar 14, 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
Tweak the form field rendering in templates, not in python-level form definitions. CSS classes and HTML attributes can be altered.

django-widget-tweaks Tweak the form field rendering in templates, not in python-level form definitions. Altering CSS classes and HTML attributes is su

Jazzband 1.8k Jan 02, 2023
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 demonstration of how a django-based website can be set up for local development with microk8s

Django with MicroK8s Start Building Your Project This project provides a Django web app running as a single node Kubernetes cluster in microk8s. It is

Noah Jacobson 19 Oct 22, 2022
Drf-stripe-subscription - An out-of-box Django REST framework solution for payment and subscription management using Stripe

Drf-stripe-subscription - An out-of-box Django REST framework solution for payment and subscription management using Stripe

Oscar Y Chen 68 Jan 07, 2023
A BitField extension for Django Models

django-bitfield Provides a BitField like class (using a BigIntegerField) for your Django models. (If you're upgrading from a version before 1.2 the AP

DISQUS 361 Dec 22, 2022
A small and lightweight imageboard written with Django

Yuu A small and lightweight imageboard written with Django. What are the requirements? Python 3.7.x PostgreSQL 14.x Redis 5.x FFmpeg 4.x Why? I don't

mint.lgbt 1 Oct 30, 2021
A Django application that provides country choices for use with forms, flag icons static files, and a country field for models.

Django Countries A Django application that provides country choices for use with forms, flag icons static files, and a country field for models. Insta

Chris Beaven 1.2k Jan 07, 2023
Wrapping Raml around Django rest-api's

Ramlwrap is a toolkit for Django which allows a combination of rapid server prototyping as well as enforcement of API definition from the RAML api. R

Jmons 8 Dec 27, 2021
Integarting Celery with Django to asynchronous tasks πŸ“ƒ

Integrating πŸ”— Celery with Django via Redis server ,To-Do asynchronously πŸ‘€task without stopping the main-flow πŸ“ƒ of Django-project . It increase your speed πŸš€ and user experience 🀡 of website

Rushi Patel 4 Jul 15, 2022