我正在尝试在 python 中编写简单的字符创建页面。我想要重新滚动统计信息的选项。问题是,刷新页面后,统计数据保持不变。下面是我的代码:
视图.py
from my import Character
...
def create_character():
characterform = CharacterForm()
if request.method == 'GET':
hero = Character()
hero.gen_stat()
return render_template('create_character.html', hero = hero, form = characterform)
我的.py
class Character():
def __init__(self):
self.attack = 0
self.defense = 0
self.hp = 0
self.ini = 0
def gen_stat(self,attack = randint(0,10), defense = randint(0,10), hp = randint(10,20), ini = randint(0,5)):
self.attack = attack
self.defense = defense
self.hp = hp
self.ini = ini
我现在正在学习python,所以很可能我做错了什么。奇怪的是,如果我在几分钟后刷新,统计数据会发生变化,所以可能与缓存有关?
请帮我解决这个问题。