To deploy your Django Application in Porter. You need to tweak something on your Django Application.
📘 Prerequisites
- Django Application
- Docker Registry integration on your account (See docs)
Install django-allow-cidr (Django middleware to enable the use of CIDR IP ranges in ALLOWED_HOSTS)
pip install django-allow-cidr
Go to Django Settings and add os.environ.get in allowed host.
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", default='127.0.0.1').split(" ")
Add this below allowed host. Put CIDR according to the K8s kubelet CIDR
ALLOWED_CIDR_NETS = os.environ.get("ALLOWED_CIDR_NETS", default='10.0.0.0/16').split(" ")
Add django-allow-cidr middleware on the top of Django middleware:
MIDDLEWARE = [
'allow_cidr.middleware.AllowCIDRMiddleware',
#'django.middleware.security.SecurityMiddleware',
]
Add Gunicorn
pip install gunicorn
Add static folder and add your HTML and CSS files. Locate static URL settings and add static file dirs below:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
Add Procfile and add this:
web: gunicorn <project-name>.wsgi -b 0.0.0.0:8989 --timeout 120
For example:
web: gunicorn djangosample.wsgi -b 0.0.0.0:8989 --timeout 120
Then pip freeze requirements
pip freeze > requirements.txt
Reference: https://github.com/jimcru21/porter-sample-django-non-docker
In Environment. Put DJANGO_ALLOWED_HOSTS that we specify on django settings. Then input your domain that you put in Configure Custom Domain.
Click Deploy then wait for buildpack to finish and push to porter. (You can see it on your repository under the Action tab )








