修复附加到多个站点的平面页面的 Django 管理预览的最佳方法
我已将平面页面附加到多个站点。其管理预览选择 任意站点,在调试到行 35-36 的 django.contrib.contenttypes.views.shortcut()
。
解决这个问题的最佳方法是什么?
我看到 shortcut()
函数采用一个 request
对象,因此我可以从那里提取主机,但我宁愿不修补实时服务器。
我还没有考虑过捕获管理网址,所以也许有人可以建议一些不错的解决方案?
I have flatpage attached to multiple sites. Its admin preview chooses
arbitrary site, which is quite obvious after debugging up to lines 35-36 ofdjango.contrib.contenttypes.views.shortcut()
.
What would be the best way of fixing this problem?
I see that the shortcut()
function takes a request
object, so I could just extract host from there, but I prefer to not patch the live server.
I haven't looked at catching admin url yet, so maybe someone can suggest some nice solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,这可以被认为是 Django 中的一个错误,至少部分修复是检查当前 SITE_ID 是否是与该对象相关的站点之一,如果是,则使用该站点而不是任意站点。您可以提交带有补丁的票证。
要在不修补 Django 的情况下修复此问题,您可以考虑覆盖 Flatpages 模型的管理编辑表单模板,以便您可以将所需的 URL 放入该链接中,而不是进入快捷方式视图的默认 URL。我还没有深入研究过它,不知道它有多干净。
另一种选择可能是使用 get_absolute_url 方法对 Flatpage 模型进行猴子补丁,该方法实际上返回一个完整的绝对 URL,包括基于 Site.objects.get_current().domain 的域。
In my opinion, this could be considered a bug in Django, and at least a partial fix would be to check if the current SITE_ID is one of the sites related to the object, and if so use that one instead of an arbitrary one. You could file a ticket with a patch.
To fix it without patching Django, you might look into overriding the admin edit-form template for the flatpages model so that you can put the URL you want into that link instead of the default one that goes to the shortcut view. I haven't looked into it enough to know how clean that would be.
Another option might be to monkeypatch the Flatpage model with a get_absolute_url method that actually returns a complete absolute url, including the domain, based on Site.objects.get_current().domain.