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!

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 What a View! First URL

is this challenge broken? https://teamtreehouse.com/library/django-basics/what-a-view/first-url

So I was just trying to wrap up some of the quizzes I skipped over. Either I'm totally not tracking today, or this challenge is broken?

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

urlpatterns = [
    path('', index)

1 Answer

18,813 Points

I haven't been through any Django stuff, and I kind of suck at regex. So unfortunately I won't be able to go into too much detail about why this is true, or any more advanced expressions, but...

My understanding is that path('', index) isn't strictly defining an empty string. I think you need r'^$' to ensure you're matching an entirely empty string. When Django encounters an empty string, I believe it will go to the index page.

Trying that along with making sure to reference views.index fixed it for me. Sorry I can't more clearly explain why this works, but maybe it will trigger your memory. 😅

url(r'^$', views.index)

smacks forehead

That would make sense. I've been using almost exclusively on 3.0 and up.... no regex in the URLs needed if you have an empty path there!

18,813 Points

I can definitely understand that. Trying to remember how to write normal JavaScript when I've used jQuery simple syntax for so long is tough - I forget all the extra stuff you need to explicitly write.