Configure Django project for public access
For Django project to work in the web browser, some additional changes may be needed.
Open the settings.py file for the Django project (inside the PROJECT_ROOT\config or PROJECT_ROOT\PROJECT_NAME folder) and follow these steps:
- Add this code to the top of the file.
import os
- Disable debug mode.
DEBUG = False
- Set ALLOWED_HOSTS for Django project remotely accessible.
- Public access to Django project:
ALLOWED_HOSTS = ['*']
- Restricted access, e.g. only requests from the 11.22.33.44 IP address:
ALLOWED_HOSTS = ['11.22.33.44']
or…
- Public access to Django project:
- Set STATIC_URL and STATIC_ROOT to serve static files.
STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'config/static')
- Build static files by executing the following command.
C:\Users\USER_NAME\Bitnami Django Stack projects\PROJECT_ROOT>python manage.py collectstatic --noinput
- Additional correcting the TIME_ZONE in settings.py file for the Django project
(inside the PROJECT_ROOT\config or PROJECT_ROOT\PROJECT_NAME folder)
#TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Bangkok'
*The config folder is the folder that contains settings.py, urls.py, wsgi.py, … inside.
This command will copy static files in folder C:\Bitnami\djangostack-3.1.4-0\apps\django\Django-3.1.4-py3.7.egg\django\contrib\admin\static to folder C:\Users\USER_NAME\Bitnami Django Stack projects\PROJECT_ROOT\config\static
We have to change something in the C:\Users\USER_NAME\Bitnami Django Stack projects\
PROJECT_ROOT\conf\httpd-app.conf, like this…
#Alias /PROJECT_ROOT/static "C:/Bitnami/djangostack-3.1.4-0/apps/django/
I suppose …. this means that we will use the static files those are inside the folder C:\Users\USER_NAME\Bitnami Django Stack projects\PROJECT_ROOT\config\static.
Django-3.1.4-py3.7.egg/django/contrib/admin/static"
Alias /mfdw_site/static "C:/Users/USER_NAME/Bitnami Django Stack projects/
PROJECT_ROOT/config/static"
Ref: Serving Static Files in Python With Django, AWS S3 and WhiteNoise