我在使用基于类的视图和 reverse_lazy 时遇到了一些奇怪的问题。
调用网站时出现以下错误:
ImproperlyConfigured at /dashboard/student/
The included urlconf core.urls doesn't have any patterns in it
我的意见.py:
class DashStudentMain(TemplateView):
model_class = None
template_name = 'learn/dashboard/snip_student_1.html'
tab_list = {
("Main", reverse_lazy('dash_student_main_url')),
#("History", reverse_lazy('dash_student_main_url'))
}
active_tab = "Main"
我的核心网址:
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
from django.views.generic import RedirectView
from django.conf import settings
admin.autodiscover()
urlpatterns = patterns(
'',
url(r'^$', 'core.views.home', name='home_url'),
url(r'^home', 'core.views.home'),
url(r'^dashboard/', include('tc_learn.dashboard.urls')),
...
)
我的 tc_learn.dashboard.urls:
from django.conf.urls.defaults import patterns, url
from .views import DashStudentMain, DashStudentHistory
urlpatterns = patterns(
# Student + Tabs
url(r"^", DashStudentMain.as_view()),
url(r"^student/$", DashStudentMain.as_view(), name="dash_student_main_url"),
url(r"^student/history/$", DashStudentHistory.as_view(), name="dash_student_history_url"),
我有
- 重新启动服务器,以确保正确加载 url
- 注释掉("Main", reverse_lazy('dash_student_main_url'))以确保 urls.py 语法正常
- 删除了url(r"^", DashStudentMain.as_view()) 行,因为它无论如何都没有使用,但是没有它 /dashboard/student 根本不起作用..
知道我可能会错过什么吗?谢谢!
编辑:看起来问题来自 tab_list 对象。当我通过 直接分配对象时tab_list = reverse_lazy('dash_student_main_url')
,代码工作正常。当我在列表中使用它时,它会显示该错误。有谁知道这种情况的解决方法?