希望我能在这里清楚地表达自己,忍受我
假设我有一个销售t恤衫的零售应用程序。每件t恤衫都可以处于预售阶段,也可以处于销售阶段
每次用户进入特定的t恤页面时,我都可以比较datetime now和它上市的日期time,确定它是预售还是在售,并输出适当的数据/内容
相反,我可以在我的t恤上有一个“phase”字符串属性,最初设置为“presale”。然后,我可以设置一个任务队列以在销售开始时执行,并将t恤的“phase”属性从“presale”切换到“in sale”。当用户访问t恤页面时,我检查字符串,不管它是“presale”还是“insale”,并输出适当的数据/内容
我的问题是,一种方法比另一种更可取吗?我假设第一个方法是datetime计算/比较,比第二个基于字符串比较的方法效率低?但是,第二种方法需要使用任务队列,这会增加开销/成本
我首先想到的是配置。它是本地的,它只是读取一个文件,它不比较任何东西
好的,我会用一个我在Django和Flask项目中经常用到的结构。我的文件夹结构通常如下所示:
My settings.py文件是变量所在的位置。它的价值是巨大的,但它的实现很简单。 我们来看一个例子:
这是我们的配置文件
现在到主应用程序,以及如何使它做一些事情
事情就是这样做的
现在,您只需要实现一个每24小时唤醒一次的小守护进程,检查
settings.json
文件上的数据,如果数据过时,请更新它(这个我会留给你XD)希望这有帮助:)
相关问题 更多 >
编程相关推荐