gpt4 book ai didi

python - Django - 包含的 urlconf 中没有任何模式

转载 作者:IT老高 更新时间:2023-10-28 21:39:05 26 4
gpt4 key购买 nike

我的网站,以前可以正常工作,突然开始出现错误

ImproperlyConfigured at / The included urlconf resume.urls doesn't have any patterns in it

项目库称为简历。在 settings.py 我已经设置了

ROOT_URLCONF = 'resume.urls'

这是我的 resume.urls,它位于项目根目录中。

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Example:
# (r'^resume/', include('resume.foo.urls')),

# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),

(r'^accounts/login/$', 'django.contrib.auth.views.login'),


#(r'^employer/', include(students.urls)),

(r'^ajax/', include('urls.ajax')),
(r'^student/', include('students.urls')),
(r'^club/(?P<object_id>\d+)/$', 'resume.students.views.club_detail'),
(r'^company/(?P<object_id>\d+)/$', 'resume.students.views.company_detail'),
(r'^program/(?P<object_id>\d+)/$', 'resume.students.views.program_detail'),
(r'^course/(?P<object_id>\d+)/$', 'resume.students.views.course_detail'),
(r'^career/(?P<object_id>\d+)/$', 'resume.students.views.career_detail'),

(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'C:/code/django/resume/media'}),

)

我有一个名为 urls 的文件夹和一个 ajax.py 文件。 (我还在同一个文件夹中创建了一个空白的 init.py 以便识别 url。)这是 ajax.py。

from django.conf.urls.defaults import *

urlpatterns = patterns('',
(r'^star/(?P<object_id>\d+)$', 'resume.students.ajax-calls.star'),
)

有人知道怎么回事吗?这让我发疯了。

谢谢,

最佳答案

TL;DR:您可能需要使用 reverse_lazy() 而不是 reverse()

如果你的 urls.py 导入一个使用 reverse() 的基于类的 View ,你会得到这个错误;使用 reverse_lazy() 将修复它。

对我来说,错误

The included urlconf project.urls doesn't have any patterns in it

被抛出是因为:

  • project.urls 导入 app.urls
  • app.urls 导入 app.views
  • app.views 有一个基于类的 View ,它使用 reverse
  • reverse 导入 project.urls,导致循环依赖。

使用 reverse_lazy而不是 reverse解决了这个问题:这将 url 的反转推迟到运行时第一次需要它为止。

道德:如果您需要在应用启动前反转,请始终使用 reverse_lazy

关于python - Django - 包含的 urlconf 中没有任何模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3011179/

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