更新时间:2023-02-24 17:53:14
在 my_config
中的模块级别定义 my_var
,然后将其导入观看次数
:
Define the my_var
at the module level in the my_config
and then import it in the views
:
my_app/my_config.py
my_var = None
class WebConfig(AppConfig):
...
def ready(self):
global my_var
my_var = {}
my_app/views.py
from my_app.my_config import my_var
def index(request):
print my_var
请注意 global
关键字.
Note the global
keyword.