Django管理站点:如何为全局设置创建单个页面? [英] Django admin site: how to create a single page for global settings?

查看:37
本文介绍了Django管理站点:如何为全局设置创建单个页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在django的管理站点中创建一个页面,可以在其中更改网站的某些全局变量(网站标题,导航菜单中的项目等).目前,我已将它们编码为上下文处理器,但我想使它们可编辑.类似于WordPress中发生的事情.

I would like to create a single page in the admin site of django where I can change some global variables of the website (title of the website, items in the navigation menu, etc). At the moment I have them coded as context processors but I would like to make them editable. Something similar to what happens in WordPress.

这可能吗?

  • 我可以将数据存储在数据库中,但是我可以在管理站点中拥有一个直接指向第一个文档记录的链接,并且不允许创建多个记录(它们没有意义)
  • 除了在数据库中创建模型外,还可以从管理站点更改一些context_processor(我认为这是最好的选择)

推荐答案

django-preferences 可以正是您要找的东西.该实现有点麻烦(特别是在模型类上设置 __ module __ ,以诱使Django认为它是从其他应用程序加载的).

django-preferences does exactly what you are looking for. The implementation is a bit hacky (particularly the setting of __module__ on the model class to trick Django into thinking it was loaded from a different app), but it works.

这篇关于Django管理站点:如何为全局设置创建单个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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