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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Dennis Mwangi](https://secure.gravatar.com/avatar/2ea37b0bcd5df0583d145ec520571ace?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Dennis Mwangi
6,835 PointsHelp in writing django urls using the url() function and regex matching
As in this project
from django.conf.urls import url, include
from . import views
urlpatterns = [
url(r'^$', views.WelcomeView.as_view()),
url(r'name/' views.NameView.as_view())
]
from django.http import HttpResponse
from django.views.generic import View, TemplateView
class WelcomeView(View):
def get(self, request):
return HttpResponse("Treehouse!")
class NameView(TemplateView):
template_name = 'name.html'
1 Answer
![Dennis Mwangi](https://secure.gravatar.com/avatar/2ea37b0bcd5df0583d145ec520571ace?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Dennis Mwangi
6,835 PointsHi carlosanroman I corrected the url to read " url(r'^name/$' views.NameView.as_view()) " but i still get an error for this practice exercise
![csr13](https://uploads.teamtreehouse.com/production/profile-photos/9998452/micro_DSC00058.webp)
csr13
33,293 PointsIf this is exacly what you typed:" url(r'^name/$' views.NameView.as_view()) " then you might need a comma after the r'^name/$' and before: views.NameView.as_view())
like this: url(r'^name/$', views.NameView.as_view())
csr13
33,293 Pointscsr13
33,293 PointsHmm your regex seems like its missing something that the one above has.
Are you sure you are matching the beginning ^ and the end $ ?
Catch my drift?
Tip:
However, if you were to be using the newest version of Django, you could be using the function path() instead of url(). .The function path() is easier, because you can just do: path('name/', .... ) instead of: url(r'name/$', ....). Nevertheless, for other types of views you would still need to use regexes with the path() function