Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在views.py 中写了一些需要一些时间来初始化的全局变量。我不想在请求后响应,而是想在服务器启动时初始化这些变量。有什么办法吗?我已经尝试谷歌但徒劳无功。我想我不可能是第一个有这种需求的人。谢谢。
您似乎在谈论 settigs,这意味着在开始时固定的变量。
您可以在其中设置此类变量settigs.py 并访问它们导入设置:
settigs.py
设置.py
MYSETTING = some expression
视图.py
from django.conf import settings ... mycalc = ... MYSETTINGS ...