Serving Django admin site on subdomain

五迷三道 提交于 2019-12-06 07:18:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!