包含的URLconf似乎没有任何模式错误

时间:2021-07-26 16:58:27

I got an error:

我收到一个错误:

  ...
  File "/Users/xxx/anaconda/envs/py36/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 'django.urls' from '/Users/xxx/anaconda/envs/py36/lib/python3.6/site-packages/django/urls/__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.

I recently updated from Django 1.8 to 2.0, so I think that's why the error happens. I think urls.py causes this error, so I rewrote it like

我最近从Django 1.8更新到2.0,所以我认为这就是错误发生的原因。我认为urls.py会导致这个错误,所以我重写了它

from django.urls import include, path

app_name = 'App'

urlpatterns = [
    path('admin/', admin.site.urls),
    path('app/', include('app.urls')),

 ] +static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

but the same error happens. I really cannot understand why this error happens. How should I fix this? What is wrong in my code?

但同样的错误发生了。我真的不明白为什么会发生这种错误。我该怎么解决这个问题?我的代码有什么问题?

2 个解决方案

#1


0  

The error says,

错误说,

django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'django.urls' from '/Users/xxx/anaconda/envs/py36/lib/python3.6/site-packages/django/urls/__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.

Could you please check your envs/py36/lib/python3.6/site-packages/django/urls/__init__.py if it has content like the following:

如果它有如下内容,请你检查你的envs / py36 / lib / python3.6 / site-packages / django / urls / __ init__.py:

from .base import (
    clear_script_prefix, clear_url_caches, get_script_prefix, get_urlconf,
    is_valid_path, resolve, reverse, reverse_lazy, set_script_prefix,
    set_urlconf, translate_url,
)
from .exceptions import NoReverseMatch, Resolver404
from .resolvers import (
    LocaleRegexProvider, LocaleRegexURLResolver, RegexURLPattern,
    RegexURLResolver, ResolverMatch, get_ns_resolver, get_resolver,
)
from .utils import get_callable, get_mod_func

__all__ = [
    'LocaleRegexProvider', 'LocaleRegexURLResolver', 'NoReverseMatch',
    'RegexURLPattern', 'RegexURLResolver', 'Resolver404', 'ResolverMatch',
    'clear_script_prefix', 'clear_url_caches', 'get_callable', 'get_mod_func',
    'get_ns_resolver', 'get_resolver', 'get_script_prefix', 'get_urlconf',
    'is_valid_path', 'resolve', 'reverse', 'reverse_lazy', 'set_script_prefix',
    'set_urlconf', 'translate_url',
]

If it does not then that is the problem, else you're using circular imports somewhere i.e., in file1.py you're doing an from file2 import var2 and in file2.py you're doing from file1 import var1.

如果没有那就是问题,否则你在某处使用循环导入,即在file1.py中你从file2 import var2和file2.py你正在从file1 import var1做。

#2


0  

try commenting below line your code

尝试在下面注释您的代码

path('app/', include('app.urls')),

this must be the cause of circular import issue. please reply if it does not work.

这必须是循环进口问题的原因。请回复,如果它不起作用。

#1


0  

The error says,

错误说,

django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'django.urls' from '/Users/xxx/anaconda/envs/py36/lib/python3.6/site-packages/django/urls/__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.

Could you please check your envs/py36/lib/python3.6/site-packages/django/urls/__init__.py if it has content like the following:

如果它有如下内容,请你检查你的envs / py36 / lib / python3.6 / site-packages / django / urls / __ init__.py:

from .base import (
    clear_script_prefix, clear_url_caches, get_script_prefix, get_urlconf,
    is_valid_path, resolve, reverse, reverse_lazy, set_script_prefix,
    set_urlconf, translate_url,
)
from .exceptions import NoReverseMatch, Resolver404
from .resolvers import (
    LocaleRegexProvider, LocaleRegexURLResolver, RegexURLPattern,
    RegexURLResolver, ResolverMatch, get_ns_resolver, get_resolver,
)
from .utils import get_callable, get_mod_func

__all__ = [
    'LocaleRegexProvider', 'LocaleRegexURLResolver', 'NoReverseMatch',
    'RegexURLPattern', 'RegexURLResolver', 'Resolver404', 'ResolverMatch',
    'clear_script_prefix', 'clear_url_caches', 'get_callable', 'get_mod_func',
    'get_ns_resolver', 'get_resolver', 'get_script_prefix', 'get_urlconf',
    'is_valid_path', 'resolve', 'reverse', 'reverse_lazy', 'set_script_prefix',
    'set_urlconf', 'translate_url',
]

If it does not then that is the problem, else you're using circular imports somewhere i.e., in file1.py you're doing an from file2 import var2 and in file2.py you're doing from file1 import var1.

如果没有那就是问题,否则你在某处使用循环导入,即在file1.py中你从file2 import var2和file2.py你正在从file1 import var1做。

#2


0  

try commenting below line your code

尝试在下面注释您的代码

path('app/', include('app.urls')),

this must be the cause of circular import issue. please reply if it does not work.

这必须是循环进口问题的原因。请回复,如果它不起作用。