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

Dylan Davenport
PLUS
Dylan Davenport
Courses Plus Student 2,645 Points

How to fix circular import??

After following this video I run the server and get this error:

ImproperlyConfigured(msg.format(name=self.urlconf_name)) django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'courses.urls' from '/home/dylan/learning_site/courses/urls.py'>' 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.

Below is the code in my learning_site urls.py file. I cannot figure out why it says there is no pattern found. I've moved some things around in other files but I won't work. If I comment out url(r'^courses/', include('courses.urls')), it will work. Any ideas?

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/', admin.site.urls), url(r'^$', views.hello_world), ]

3 Answers

Ryan S
Ryan S
27,276 Points

Hey Dylan,

I think the problem is the way you typed "url_patterns" in courses/urls.py.

It should be "urlpatterns" without the underscore.

Dylan Davenport
Dylan Davenport
Courses Plus Student 2,645 Points

That did the trick. Haha I can't believe I didn't notice that. Thank you.

Ryan S
Ryan S
27,276 Points

No problem. I've made that same mistake before too. With standard Python naming conventions it seems natural to want to put an underscore in there.

Ryan S
Ryan S
27,276 Points

Hi Dylan,

The error message seems to indicate that there is something wrong with your 'courses/urls.py', (not learning_site/urls.py). If commenting out the 'includes' line makes the error go away then I would suggest going through the courses urls.py. You can post the code for that file too if you need more help debugging.

Good luck.

Dylan Davenport
PLUS
Dylan Davenport
Courses Plus Student 2,645 Points

Here is the code for my courses urls.py file:

from django.conf.urls import url from . import views

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

I still can't figure it out haha.