【问题标题】:Trying to run Django and getting AttributeError: module 'secrets' has no attribute 'choice'试图运行 Django 并得到 AttributeError: module 'secrets' has no attribute 'choice'
【发布时间】:2021-05-28 12:05:15
【问题描述】:

''' 文件“/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/management/init.py”,第 395 行,在执行 self.fetch_command(子命令).run_from_argv(self.argv) 文件“/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/management/base.py”,第 330 行,在 run_from_argv self.execute(*args, **cmd_options) 文件“/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/management/base.py”,第371行,在执行 输出 = self.handle(*args, **options) 文件“/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/management/commands/startproject.py”,第 18 行,在句柄中 选项['secret_key'] = get_random_secret_key() 文件“/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/core/management/utils.py”,第 82 行,在 get_random_secret_key 返回 get_random_string(50, 字符) 文件“/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/utils/crypto.py”,第 74 行,在 get_random_string return ''.join(secrets.choice(allowed_chars) for i in range(length)) 文件“/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/django/utils/crypto.py”,第 74 行,在 return ''.join(secrets.choice(allowed_chars) for i in range(length)) AttributeError:模块“秘密”没有属性“选择” '''

【问题讨论】:

  • 已修复。我不小心删除了秘密文件并将我的一个密钥作为 secrets.py

标签: django


【解决方案1】:

确保您的 python 路径和/或当前工作目录中没有任何名为 secrets 的文件或文件夹。这可能会影响内置的 secrets 模块。

【讨论】:

    猜你喜欢
    • 2022-12-01
    • 2022-10-19
    • 1970-01-01
    • 2022-08-04
    • 2014-05-08
    • 2020-03-26
    • 2020-09-24
    • 2015-09-26
    • 2020-11-23
    相关资源
    最近更新 更多