gpt4 book ai didi

python-如何在Flask中设置全局变量?

转载 作者:太空狗 更新时间:2023-10-29 17:05:14 26 4
gpt4 key购买 nike

<分区>

我正在做一个 Flask 项目,我想让我的索引在滚动时加载更多内容。我想设置一个全局变量来保存页面加载了多少次。我的项目结构如下:

├──run.py
└──app
├──templates
├──_init_.py
├──views.py
└──models.py

首先,我在_init_.py中声明了全局变量:

global index_add_counter

Pycharm 警告 Global variable 'index_add_counter' is undefined at the module level

views.py中:

from app import app,db,index_add_counter

还有 ImportError: cannot import name index_add_counter

我还引用了 global-variable-and-python-flask但是我没有 main() 函数。在 Flask 中设置全局变量的正确方法是什么?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com