gpt4 book ai didi

python - 尝试使用 django-subdomains 在我的 django urlpatterns 中查找循环引用?

转载 作者:行者123 更新时间:2023-12-01 03:50:46 25 4
gpt4 key购买 nike

我正在为我的网络应用程序获取正确的 url 配置,但我却无所事事。

认为django-subdomains背后的想法子域路由存储在SUBDOMAIN_URLCONFS

ROOT_URLCONF = 'creativeflow'
# A dictionary of urlconf module paths, keyed by their subdomain.
SUBDOMAIN_URLCONFS = {
None: ROOT_URLCONF + '.urls', # no subdomain, e.g. ``example.com``
'www': ROOT_URLCONF + '.urls',
'blog': 'blog.urls',
}

然后我的creativeflow.urlsblog.urls是:

"""Creativeflow URL Configuration."""
from django.conf.urls import url
from django.contrib import admin

urlpatterns = [
url(r'^admin/', admin.site.urls, name="admin"),
]

还有

"""Creativeflow URL Configuration the blog app."""
from django.conf.urls import url
from .views import BlogListView
urlpatterns = [
url(r'posts/^(?P<year>\d{4})/(?P<months>\d{2}|\w{3})/(?P<day>\d{2})',
BlogListView.as_view(paginate_by=25), name="blog-list-view")
]

我看到的错误是:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x046FA618>
Traceback (most recent call last):
File "D:\creativeflow\myvenv\lib\site-packages\django\core\urlresolvers.py", line 419, 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 "D:\creativeflow\myvenv\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "D:\creativeflow\myvenv\lib\site-packages\django\core\management\commands\runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "D:\creativeflow\myvenv\lib\site-packages\django\core\management\base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "D:\creativeflow\myvenv\lib\site-packages\django\core\checks\registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "D:\creativeflow\myvenv\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "D:\creativeflow\myvenv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "D:\creativeflow\myvenv\lib\site-packages\django\utils\functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "D:\creativeflow\myvenv\lib\site-packages\django\core\urlresolvers.py", line 426, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf 'creativeflow' 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 中都有一个 urlpatterns。所以我必须有一个循环引用。但我通过 views.pymodels.py 跟踪了导入,没有看到任何会导致循环依赖问题的内容。

如何解决这个问题/并找到循环依赖?

最佳答案

您的ROOT_URLCONF指向一个没有任何模式的模块。 ROOT_URLCONF模块必须至少有一个urlpatterns属性,即使它是一个空列表。您可能希望它指向creativeflow.urls

关于python - 尝试使用 django-subdomains 在我的 django urlpatterns 中查找循环引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38294394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com