How can I disable Django's admin in a deployed project, but keep it for local development?

First, establish a scheme so that your production server can have different settings than your development servers. A simple way to do that is with a source-control-ignored local_settings.py file, but there are many fancier ways to do it.

Then, in your settings.py file, put:

ADMIN_ENABLED = True

and in your production-only settings file, put:

ADMIN_ENABLED = False

Then in your urls.py:

if settings.ADMIN_ENABLED:
    urlpatterns += patterns('',
        (r'^admin/(.*)', include(admin.site.urls)),
        # ..maybe other stuff you want to be dev-only, etc...
        )

Extending @NedBatchelder 's answer, you might want to use proper if statement, like this:

if settings.ADMIN_ENABLED is True:
    ...

And also remove 'django.contrib.admin' from INSTALLED_APPS = [...], and use the same condition:

if settings.ADMIN_ENABLED is True:
    INSTALLED_APPS.append('django.contrib.admin')

This way the module wont be loaded, and for eg. collectstatic wont copy unnecessary static files used only in admin (fonts, images, css, js).

Tags:

Python

Django