开发者

How import between multi-site Django projects

How can I import models and views from Django Site1 to Site2 using the Sites Framework?

Django Sites Framework scenario

top

  ----site1

  ----site2

  ----media


#开发者_高级运维File on Site 2: views.py

from site1.article.models import Model1, Model2


Django's sites framework is about sharing the same code on different sites (in the end different Django instances with one codebase and one database).

Your directory structure suggests that you are doing it wrong: you should not have multiple site apps, putting your stuff in site1 and importing it into other site apps.

Instead you should code your Django Apps with the help of the sites framework:

  • add a site reference to your models where it makes sense
  • setup multiple Django instances each with its own SITE_ID in settings.py
  • your model objects can then be filtered by Site.objects.get_current()

You can do this in elaborate ways (Model inheritance, custom Managers for automatic filtering), but this is the basic description.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜