【问题标题】:I get an error while trying to create superuser尝试创建超级用户时出现错误
【发布时间】:2019-09-20 23:25:17
【问题描述】:

我是 Django 的新手,我正在尝试创建一个超级用户(我在 Linux mint 上),每次我遇到一个非常奇怪的错误,这是我在其他 Django 项目中没有遇到的。错误如下:(除了在已安装的应用程序列表中添加我的应用程序和在 urls 中应用程序的 url 之外,我没有修改 django 项目中的任何内容。)

  File "/home/user/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 538, in url_patterns
    iter(patterns)
TypeError: 'module' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/user/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/home/user/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/user/.local/lib/python3.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 59, in execute
    return super().execute(*args, **options)
  File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 332, in execute
    self.check()
  File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 364, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 351, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/registry.py", line 73, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/home/user/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 398, in check
    warnings.extend(check_resolver(pattern))
  File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/home/user/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 397, in check
    for pattern in self.url_patterns:
  File "/home/user/.local/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/user/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 545, in url_patterns
    raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'pleasework' from '/home/user/example.com/attempt/pleasework/__init__.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.

你能告诉我我做错了什么吗?我尝试创建一个虚拟环境,但它不起作用。

【问题讨论】:

  • 你的主要 urls.py 是什么

标签: python django superuser


【解决方案1】:

请添加更详细的代码,以便我可以更好地提供帮助,无论如何,请尝试以下 -

  1. 使用--username 标志而不是直接传递用户名:
python manage.py createsuperuser --username yourusername
  1. 确保您在 admin.py 文件中正确导入了模型。
  2. 检查此行是否出现在 INSTALLED_APPS 中:
'django.contrib.admin',
  1. 尝试迁移更改,然后运行 ​​createsuperuser。

我希望其中一个能解决问题。

【讨论】:

    【解决方案2】:
    1. 要检查迁移,请运行 python3 manage.py migrate
    2. 检查出现在&lt;project_root&gt;/&lt;project&gt;/settings.pyINSTALLED_APPS 列表中的行。

    然后使用python3 manage.py createsuperuser 应该可以正常工作。它应该会提示您:

    Username (leave blank to use '<user>'):
    E-mail: 
    Password:
    

    &lt;user&gt; 是您计算机的用户名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      相关资源
      最近更新 更多