ozcanyarimdunya / dj_noto_nginx

A django application in production without Nginx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No to Nginx!

Serve your static files with whitenoise and media files with dj-static in production mode.

Live demo: https://no-to-nginx.herokuapp.com/

Usage

Change below files:

config/wsgi.py

from dj_static import MediaCling

application = MediaCling(get_wsgi_application())

config/settings.py

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',  # 3rd party: static files handler
    # rest of the middleware
]

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'assets', 'staticfiles')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'assets', 'static')
]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

if os.getenv('MODE') == 'PRODUCTION':
    DEBUG = False
    DATABASES['default'] = dj_database_url.config(conn_max_age=600)  # search for env: `DATABASE_URL`

Run with docker-compose

Run below commands and visit http://localhost:8000/

docker-compose up -d --build

ss

ss

About

A django application in production without Nginx


Languages

Language:Python 62.2%Language:HTML 29.3%Language:CSS 4.1%Language:Shell 2.5%Language:Dockerfile 2.0%