-1

我在 python 中使用了一个随机函数,但它不起作用,我对 python 很陌生。请查看以下代码

  def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['number'] = random.randrange(1, 100)
        return context

其重新调整错误 NameError: name 'random' is not defined

4

1 回答 1

0

可能,您没有导入随机模块。将此添加到脚本的顶部:

import random 
于 2018-10-10T06:29:31.147 回答