不为成仙,只为在这红尘中等你回来。

您现在的位置是:网站首页>>Django

天天生鲜 The included URLconf 'dailyfresh.urls' does not appear to have any patterns in it.

2019年8月12日 18:13 | 分类:Django | 标签: Python Django

问题描述

Python3.5 + Django2.2 天天生鲜项目在注册基本逻辑一节中运行($ python3 manage.py runserver)时出现如下报错:

(venv) fang@ubuntu:~/dailyfresh$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/home/fang/dailyfresh/venv/lib/python3.5/site-packages/django/urls/resolvers.py", line 581, 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 "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/home/fang/dailyfresh/venv/lib/python3.5/site-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/home/fang/dailyfresh/venv/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    self.check(display_num_errors=True)
  File "/home/fang/dailyfresh/venv/lib/python3.5/site-packages/django/core/management/base.py", line 390, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/fang/dailyfresh/venv/lib/python3.5/site-packages/django/core/management/base.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/fang/dailyfresh/venv/lib/python3.5/site-packages/django/core/checks/registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/fang/dailyfresh/venv/lib/python3.5/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "/home/fang/dailyfresh/venv/lib/python3.5/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "/home/fang/dailyfresh/venv/lib/python3.5/site-packages/django/utils/functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/fang/dailyfresh/venv/lib/python3.5/site-packages/django/urls/resolvers.py", line 588, in url_patterns
    raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf 'dailyfresh.urls' 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.

出错原因

未知,反正一导入用户模型就报错(from .models import User)。

解决方法

修改 settings 配置文件中的 INSTALLED_APPS

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'tinymce',
    'apps.user',
    'apps.goods',
    'apps.cart',
    'apps.order',
]

修改前是这样的

INSTALLED_APPS = [
    ...
    'tinymce',
    'user',
    'goods',
    'cart',
    'order',
]