Python (Django)

Deploy Django Application (Non-Dockerize)

To deploy your Django Application in Porter. You need to tweak something on your Django Application.



  • Django Application
  • Docker Registry integration on your account (See docs)

Prepare Django Application

  1. Install django-allow-cidr (Django middleware to enable the use of CIDR IP ranges in ALLOWED_HOSTS)
pip install django-allow-cidr
  1. Go to Django Settings and add os.environ.get in allowed host.
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", default='').split(" ")
  1. Add this below allowed host. Put CIDR according to the K8s kubelet CIDR
ALLOWED_CIDR_NETS = os.environ.get("ALLOWED_CIDR_NETS", default='').split(" ")
  1. Add django-allow-cidr middleware on the top of Django middleware:
  1. Add Gunicorn
pip install gunicorn
  1. Add static folder and add your HTML and CSS files. Locate static URL settings and add static file dirs below:
  os.path.join(BASE_DIR, 'static'),
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
  1. Add Procfile and add this:
web: gunicorn <project-name>.wsgi -b --timeout 120 

For example: 

web: gunicorn djangosample.wsgi -b --timeout 120
  1. Then pip freeze requirements
pip freeze > requirements.txt


Deploy Django in Porter

  1. Click Web Service then Launch Template
  2. Name your application. ex. django-sample


  1. In Deployment Method. Connect git repo. After that, select repo. ( ex. porter-sample-django-non-docker )


  1. Click Main then continue



  1. Click web then choose an image destination ( ex. mine is aws (see image) )



  1. Then in Destination, just leave it default.

  2. In Additional settings, specify the container port that you use in gunicorn in Procfile ( ex. 8989).
    You can configure your domain, click Configure Custom Domain then put your desire domain name (im using the default porter domain)


  3. In Environment. Put DJANGO_ALLOWED_HOSTS that we specify on django settings. Then input your domain that you put in Configure Custom Domain.


  4. Click Deploy then wait for buildpack to finish and push to porter. (You can see it on your repository under the Action tab )