问题
I have a project running Django, uWSGI, and Nginx. Currently I use the default Django admin site, served at example.com/admin
. I want to change this so that the admin site is only available at admin.example.com
.
What is the best way to do this?
I had thought about starting a completely new Django project to be served on admin.example.com
but with the same database settings as the project that runs example.com
, but I'm hoping for something more elegant since this would involve duplicating a lot of the settings and apps between the projects. Basically the only difference between the two would be that one would have the admin site and URL pattern installed and one would not.
(My reason for this is eventually wanting to use something like google auth proxy to protect the admin site but have non-admin logins go through the normal authentication backend. It looks like I could do this by specifying that Django use HTTP Basic Auth for admin.example.com
, but stick with the default backend for example.com
.)
回答1:
Just create a new settings file which includes the original settings and defines a special ROOT_URLCONF
setting. Now you simply need to deploy your app with that DJANGO_SETTINGS_MODULE
on that admin subdomain.
e.g.:
settings_admin.py
from settings import *
ROOT_URLCONF = 'urls_admin'
urls_admin.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'', include(admin.site.urls)),
)
来源:https://stackoverflow.com/questions/26004217/serving-django-admin-site-on-subdomain