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

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

问题描述

我要服侍了专门的RSS订阅源从网站的其余部分不同的子域。

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

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

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:

<一个href=\"http://effbot.org/zone/django-multihost.htm\">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.

其基本思想是将 SITE_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.

它的工作原理pretty以及:),它的生产在 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 如果你希望,因为没有什么是使用同样的preventing您 ROOT_URLCONF 中的所有网站 settings.py 文件...或者你可以有diffent为每个站点。在这种情况下,你将要包括的子URL到prevent重复自己的任何普通的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和/或<一href=\"http://$c$c.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIProcessGroup\">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的主机名(请参阅Htt$p$pquest.get_host() Django文档)。对于这个问题,尽管这将是一个轻微的性能损失,你可以把你所有的意见的装饰,检查传入主机。

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.

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

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