Hey Sivanudh, Sorry, I misunderstood your question.

To separate the admin site from the “main” site, we added a variable in settings.py called IS_ADMIN. Then, for example, to load different url’s for admin and main we have this in the settings.py:

if IS_ADMIN:
ROOT_URLCONF = 'conf.admin_urls'
else:
ROOT_URLCONF = 'conf.urls'

We also use this variable to populate MIDDLEWARE, INSTALLED_APPS etc…

To make settings aware of the site it is running, we use an environment variable. Our convention is {APP_NAME}_INSTANCE=site|admin where “site” is the default.

For example, to run an admin instance:

APP_INSTANCE=admin ./manage.py runserver 8002

To run an instance of site:

APP_INSTANCE=site ./manage.py runserver

Or, just:

./manage.py runserver

This works because “site” is the default.

This is a bit outside what most people are used to, so we added a helpful snippet in settings.py to remind developers to set this when necessary:

import os, systry:
instance = os.getenv('APP_INSTANCE', 'site')
if instance not in ('site', 'admin'):
raise ValueError()
IS_ADMIN = instance == 'admin'
except Exception:
print('''
Could not find which APP instance type to use.
You must set the APP_INSTANCE environment variable to either "site" or
"admin" (if unset, the default is "site").
Example:
APP_INSTANCE=admin ./manage.py runserver

''', file=sys.stderr)
sys.exit(1)

In production you run two instances of Django. One with site and one with admin.

Hope this answers your question ;)

Written by

Full Stack Developer, Team Leader, Independent. More from me at https://hakibenita.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store