【问题标题】:Django makemigrations, 'module' object is not iterableDjango makemigrations,“模块”对象不可迭代
【发布时间】:2021-09-09 16:16:54
【问题描述】:

我是 Django 新手,我正在尝试使用模型和迁移,在我尝试执行命令之前一切正常:python manage.py makemigrations 它引发错误的地方:

TypeError: 'module' 对象不可迭代

我尝试重新安装 Django 并在我的代码编辑器上创建一个新的 venv 并更改设置,基本上我可以在网上找到所有内容,但我遇到了这个错误(完整如下)。

Traceback (most recent call last):
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\urls\resolvers.py", line 591, in url_patterns
    iter(patterns)
TypeError: 'module' object is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\core\management\base.py", line 368, in execute
    self.check()
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\core\management\base.py", line 396, in check
    databases=databases,
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\core\checks\urls.py", line 23, in check_reso`enter code here`lver
    return check_method()
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\urls\resolvers.py", line 409, in check
    messages.extend(check_resolver(pattern))
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
    return check_method()
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\urls\resolvers.py", line 408, in check
    for pattern in self.url_patterns:
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\Emanuele\Desktop\Django_Env\lib\site-packages\django\urls\resolvers.py", line 598, in url_patterns
    raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'flights.urls' from 'C:\\Users\\Emanuele\\Desktop\\Airline\\flights\\urls.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.

【问题讨论】:

  • 告诉我们flights.urls

标签: python django


【解决方案1】:

在您的 flights 应用程序中,您必须创建一个名为 urls.py 的文件(如果存在)而不是添加新文件,然后您必须添加 urlpatterns在你的 urls.py

将此添加到您的 flights/urls.py

app_name="flights"

urlpatterns = [

]

【讨论】:

    【解决方案2】:

    尝试使用python manage.py makemigrations(插入您的 Django 应用名称)

    【讨论】:

      【解决方案3】:

      再次检查你的拼写我有 urlpatters [] 而不是 urlpatterns = [] 并给出了同样的错误。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-15
        • 1970-01-01
        • 2012-08-10
        • 2021-07-04
        • 2021-02-04
        • 2020-02-28
        • 2013-05-07
        • 2019-07-25
        相关资源
        最近更新 更多