数据库表中的 Django 设置值
是否可以从数据库表中设置 settings.py 中变量的值?
我正在使用 endless_pagination
并且它有一个可覆盖设置
ENDLESS_PAGINATION_PER_PAGE = 10
,
我需要使用数据库表中的值来设置此值,可以吗?
喜欢
config = Config.objects.get(param_name__exact="ENDLESS_PAGINATION_PER_PAGE")
settings.ENDLESS_PAGINATION_PER_PAGE= config.param_value
Is it possible to set the values for the variables in settings.py from a database table?
I'm using endless_pagination
and it has a overwrite-able setting
ENDLESS_PAGINATION_PER_PAGE = 10
,
I need to set this value with a value from my database table, is it possible?
like
config = Config.objects.get(param_name__exact="ENDLESS_PAGINATION_PER_PAGE")
settings.ENDLESS_PAGINATION_PER_PAGE= config.param_value
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据他们的文档,此变量可以被模板标记覆盖:
来源:http://code.google.com/p/django-endless-pagination/source/browse/endless_pagination/templatetags/endless.py
更新:使用这个事实,您可以设置视图中传递给模板的变量:
According to their documentation, this variable can be overwritten by your template tag:
Source: http://code.google.com/p/django-endless-pagination/source/browse/endless_pagination/templatetags/endless.py
Update: using this fact, you can set a variable in your View which gets passed to the template: