在子域上提供Django管理网站 [英] Serving Django admin site on subdomain

查看:104
本文介绍了在子域上提供Django管理网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行Django,uWSGI和Nginx的项目.目前,我使用默认的Django管理站点,位于example.com/admin.我想更改此设置,以使管理站点仅在admin.example.com可用.

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?

我曾考虑过要在admin.example.com上启动一个全新的Django项目,但要与运行example.com的项目具有相同的数据库设置,但是我希望有一些更优雅的方法,因为这将涉及到复制一个项目之间的许多设置和应用.基本上,两者之间的唯一区别是,一个将安装管理站点和URL模式,而另一个则不会.

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.

(我的最终目的是想使用类似 google auth proxy 保护管理员站点,但让非管理员登录通过正常的身份验证后端,看来我可以通过指定Django对admin.example.com使用HTTP基本身份验证来做到这一点,而对example.com使用默认后端>.)

(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.)

推荐答案

只需创建一个包含原始设置并定义特殊ROOT_URLCONF设置的新设置文件.现在,您只需要在该管理子域上使用该DJANGO_SETTINGS_MODULE部署您的应用程序即可.

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.

例如:

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)),
)

这篇关于在子域上提供Django管理网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆