Architecture of multiple Sites

已查看 78 次
跳至第一个未读帖子

jorr...@gmail.com

未读,
2016年3月21日 21:08:272016/3/21
收件人 Django users
I'm wondering if I understand the Sites framework correctly... I'm building a forum-like project which will initially be accessible from mydomain.com . The project contains several apps like posts, members, ads, etc. Eventually I would like to create myseconddomain.com, which would have unique posts, but share the members, ads, etc. apps and look the same as the first site except for the domain name and title in the header. The code will be identical to the first site. Can I achieve this with a single project and several SITE_IDs, or am I correct in thinking that the Sites framework is only for sharing the same database across projects, and not the code files? And if there is a way to share the code files, how do you get around the fact that you set SITE_ID once in settings.py?

Thanks in advance for the help!

Sai Kiran

未读,
2016年3月22日 08:33:392016/3/22
收件人 Django users
If you need to use single projects for more than domains, create an entry in django_site model by giving domain as well as verbose name. Don't give any SITE_ID in settings.py, instead of this you can use Site.objects.get_current() in your view and compare the domain names and change the header accordingly.

Please feel free to correct me if I'm wrong.

jorr...@gmail.com

未读,
2016年3月22日 11:21:412016/3/22
收件人 Django users
But if I don't set the SITE_ID in settings.py I can't use the CurrentSiteManager, correct?

Sai Kiran

未读,
2016年3月23日 08:39:202016/3/23
收件人 Django users
You can try something like below:
  class CustomSiteManager(CurrentSiteManager):
    def get_queryset(self):
current_site = Site.objects.get_current()
return super(CustomSiteManager, self).get_queryset().filter(
**{self._get_field_name() + '__id': current_site.id})

We are trying to extend the CurrentSiteManager and slightly modified the method get_queryset. By using this way no need to set SITE_ID in settings.

We need to refer CustomSiteManager instead of CurrentSiteManager in all of your models.

dh...@edx.org

未读,
2016年3月23日 10:43:452016/3/23
收件人 Django users
We ran into this problem and decided to extend Django's CurrentSiteMiddleware to allow for the specification of a default site to use in the case when you cannot determine the current site from the host of the incoming request.


jorr...@gmail.com

未读,
2016年4月5日 19:49:542016/4/5
收件人 Django users
These are both interesting solutions. I will give them a try, thanks!
回复全部
回复作者
转发
0 个新帖子