Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: The included urlconf core.urls doesn't have any patterns in it

I'm having some weird issues with class-based-views and reverse_lazy.

Following error shows up when calling the website:

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

My views.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"

My core.urls:

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')),
    ...
)

My 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"),

I've

  • restarted the server, to make sure urls were loaded properly
  • commented out ("Main", reverse_lazy('dash_student_main_url')) to make sure that the urls.py syntax is fine
  • deleted the line url(r"^", DashStudentMain.as_view()), since it's not used anyway, but without it /dashboard/student doesn't work at all..

Any idea what I might be missing? Thanks!

EDIT: It looks like the issue is coming from the tab_list object. When I directly assign the object via tab_list = reverse_lazy('dash_student_main_url'), the code works fine. When I use it inside a list, it's showing that error. Does anyone know of work-around for this scenario?

like image 879
Joseph jun. Melettukunnel Avatar asked Dec 20 '22 23:12

Joseph jun. Melettukunnel


2 Answers

Change this code:

tab_list = {
    ("Main", reverse_lazy('dash_student_main_url')),
    #("History", reverse_lazy('dash_student_main_url'))
}

to:

tab_list = [
    ("Main", reverse_lazy('dash_student_main_url')),
    #("History", reverse_lazy('dash_student_main_url'))
]

Contrary to a name you gave the variable, you were not creating a list, but a set. Elements were evaluated immediately at the time of set creation, because sets need to know more about values they contain. Changing it to a proper list will allow the elements to be evaluated lazily, as intended.

like image 98
Ludwik Trammer Avatar answered May 20 '23 15:05

Ludwik Trammer


In tc_learn.dashboard.urls: you are missing the first argument (empty prefix in your case). Change it to:

urlpatterns = patterns(
    '',
    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"),
)

Also, the first regex should be r"^$" if you want it to represent an empty one And see if it works. Let me know!

like image 28
Alvaro Avatar answered May 20 '23 13:05

Alvaro