“站点框架”在一个django实例上 [英] "sites framework" on a single django instance

查看:160
本文介绍了“站点框架”在一个django实例上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在其他网站的不同子域上提供专门的RSS提要。

I want to serve up specialized RSS feeds on a different subdomain from the rest of the site.

我可以使用网站框架使用不同的urls.py和一个django实例中的settings.py文件 。或者我需要设置两个apache位置,只需在apache conf中设置不同的settings.py文件。

Can I use the sites framework to use a different urls.py and settings.py file within a single django instance. or do I need to set up two apache locations and just set the different settings.py files in the apache conf.

我需要设置两个urls.py的原因文件是避免重复的内容。我不希望在rss.example.com上提供主要的网站,我不希望在example.com上访问专门的信息。

The reason I need to set up two urls.py files is to avoid duplicate content. I don't want the main site to be available at rss.example.com and I don't want the specialized feeds to be accessible on example.com

为他们提供服务从一个单一的django实例将是理想的,因为我们在共享托管有限的内存,似乎有这样的浪费,有一个实例打开,只提供rss。

Serving them from a single django instance would be ideal because we're on shared hosting with limited memory, and it seems like such a waste to have an instance open that only serves up rss.

编辑:我的结论是,使用单独的urls.py文件的多个实例对我来说最简单...但是我发现这篇文章描述了如何使用单个实例:

edit: I concluded that multiple instances with seperate urls.py files would be easiest for me... but I found this article describing how to do it using a single instance:

http://effbot.org/zone/django-multihost .htm

我最终写了一个在单个django实例上运行多个站点副本的框架。

I ended up writing a framework for running multiple copies of a site on a single django instance.

基本思想是更改 S ITE_ID 为每个请求运行设置,并从数据库加载备用设置。它基于域名,并且默认情况下使用 SITE_ID = 1 (当它找不到任何东西)

The basic idea is to change out the SITE_ID setting on the fly for each request and load alternate settings from the database. It does this based on domain and uses SITE_ID = 1 by default (when it can't find anything)

settings.py文件中的所有设置都作为默认值,由当前站点的数据库中存储的设置覆盖。

All settings in the settings.py file act as defaults which are overridden by the settings stored in the database for the current site.

它的工作原理很好:)它正在运行在 http://rootbuzz.com 的生产中

It works pretty well :) and it's running in production at http://rootbuzz.com

推荐答案

使用库存Django,您必须为每个站点都有唯一的 settings.py ,因为SITE_ID在 settings.py ,是哪个网站正在处理此请求的关键。

With stock Django you must have a unique settings.py for each site... because the SITE_ID is defined in settings.py and is the key for which site is handling this request.

换句话说,SITE_ID对您的实例是全局的,因此您需要每个站点的一个实例。

In other words, SITE_ID is global to your instance and therefore you need an instance for each site.

如果你愿意,你可以有一个常见的 urls.py ,因为没有任何东西您在所有网站中使用相同的 ROOT_URLCONF settings.py 文件...或者您可以h对于每个站点,ave是不同的一个。在这种情况下,您需要包含子网址,以防止重复使用任何常见的URL。

You can have a common urls.py if you wish because there's nothing preventing you from using the same ROOT_URLCONF in all your site settings.py files... or you can have diffent one for each site. In this case you would want to include sub URLs to prevent repeating yourself for any common URLs.

至少有两种方法可以尝试从单个实例中提供:

There are at least two methods you can try to serve from a single instance:


  1. 使用apache + mod_wsgi ,并使用 WSGIApplicationGroup 和/或 WSGIProcessGroup 指令。我从来没有需要这些,所以不能完全确定这些将按照你想要的方式工作,但无论你是否可以使用mod_wsgi在守护进程模式下大大提高内存占用。

  1. Use apache + mod_wsgi and use the WSGIApplicationGroup and/or WSGIProcessGroup directives. I've never needed these before so can't be completely sure these will work the way you want, but regardless you can definitely use mod_wsgi in daemon mode to greatly improve your memory footprint.

您可以使用Django中间件根据请求主机名来拒绝/允许URL(请参阅 HttpRequest.get_host())。对于这个问题,即使这样做会有轻微的表现,您可以在所有查看收件人的视图上放置装饰器。

You can play with Django middleware to deny/allow URLs based on the request hostname (see HttpRequest.get_host() in the Django docs). For that matter, even though it would be a slight performance hit, you can put a decorator on all your views that checks the incoming host.

这篇关于“站点框架”在一个django实例上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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