Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Basics Model Administration First App View

Jennifer Liu
Jennifer Liu
1,636 Points

When I tried to run the program. I keep getting a 'Courses not found error'. Why?

from django.conf.urls import include, url
from django.contrib import admin
from . import views

urlpatterns = [
    url(r'^courses/',include(courses.urls)),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$',views.hello_world),
]

Here is the code for my url.py of learning_site app. I tried importing the Courses app as well but that didn't seem to work either

4 Answers

David Axelrod
David Axelrod
36,073 Points

I think you are forgeting to add the namespace

from . import views

urlpatterns = [
    url(r'^courses/', include('courses.urls', namespace='courses')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', views.hello_world),
]
Jennifer Liu
Jennifer Liu
1,636 Points

Wow, Thank you so much!! It worked!! Can you explain to me when I should use " " and when not to. Because, for the admin, when I tried putting it as string, it did not work. Thanks!

Jennifer Liu
Jennifer Liu
1,636 Points

That did not seem to work either

David Axelrod
David Axelrod
36,073 Points

Sorry to hear that :/ Maybe you havent imported it yet?

Jennifer Liu
Jennifer Liu
1,636 Points

Oh yeah, so I added the import statement.

from django.conf.urls import include, url
from django.contrib import admin
import courses

urlpatterns = [
    url(r'^courses/',include(courses.urls)),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$',views.hello_world),

]

It worked but when i try to run it on the server, I am getting another error. It says from module courses has no attribute url. Do you know why that is.

Inside the urls.py file inside courses module, I have this code:

from django.conf.urls import url

from . import views   

urlpatterns = [
  url(r'^$',views.course_list),
]

Thanks a lot for the help by the way!

David Axelrod
David Axelrod
36,073 Points

not a problem!!

i think include also takes strings so try "courses.urls"

if that doesnt work, let me know the full error statement