简体   繁体   English

应用的Django自定义设置

[英]Django custom settings for app

I am currently developing an app for django that needs to have some custom settings that can be changed at runtime by admin users, and those settings have to be accessible to another separate system that uses the same database. 我目前正在为django开发一个应用程序,该应用程序需要一些自定义设置,管理员可以在运行时更改这些设置,并且这些设置必须可由使用同一数据库的另一个单独的系统访问。

On one hand, we could store those settings in a json file and have it accessible to both systems, as only the django system will actually make any changes to the settings. 一方面,我们可以将这些设置存储在一个json文件中,并且两个系统都可以访问它,因为只有django系统才能对设置进行任何更改。 On the other hand, we could just store those settings as a lone row in on a 'settings' table on the database. 另一方面,我们可以将这些设置作为单独的行存储在数据库的“设置”表中。

The first choice seems quite cumbersome to deal with, and might result in some problems of multiple accesses, while the other would need a whole table in the database for a single row. 第一种选择似乎很麻烦,并且可能导致多次访问的问题,而另一种则需要数据库中的整个表用于一行。

Is any of these ideas any good, or is there something I'm overlooking? 这些想法中的任何一个是好的,还是我忽略了什么?

Make a table. 做一张桌子。 Remember, Django makes it really easy . 记住,Django使它变得非常容易 Just create another class for the settings table and populate it. 只需为设置表创建另一个类并填充它。 You should be able to access it with just about any other language/system - eg, PHP. 您应该几乎可以使用任何其他语言/系统(例如PHP)来访问它。 The data gets backed up with everything else in the database, if you move to a different server the data moves along with everything else, etc. Yes, the overhead is technically a little more than a plain text file, but if it is really that small then that overhead is insignificant. 数据将与数据库中的其他所有内容一起备份,如果移至其他服务器,则数据将与其他所有内容一起移动,依此类推。是的,从技术上讲,开销比纯文本文件略多,但是如果确实如此,很小,那么开销是微不足道的。 If the list of settings grows over time then having it in a searchable database will make updates & retrieval much easier that a text file. 如果设置列表随时间增长,那么将其保存在可搜索的数据库中将使更新和检索比文本文件容易得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM