I am currently working in a Django project for which I need access to the admin area for local development, but want to disable it in the deployed site (for security reasons, am
@madneon 's answer is terrific but requires an update and a small correction, and unfortunately the suggested edit queue is full.
For the first part, as it implies the use of @Ned Batchelder 's answer, the use of patterns()
is no longer supported in Django 1.9 and above.
A current implemention could look like:
from django.conf import settings
from django.urls import path
urlpatterns = []
if settings.ADMIN_ENABLED is True:
urlpatterns += [path('admin/', admin.site.urls),]
urlpatterns += [
# ... Other paths
]
For the second part regarding appending to INSTALLED_APPS
, this needs to go in the settings.py file and cannot be placed in the urls files.
As such, it should be written:
if ADMIN_ENABLED is True:
INSTALLED_APPS.append('django.contrib.admin')
If you include settings.
before ADMIN_ENABLED
you'll get an error.