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

1 Answer

diogorferreira
diogorferreira
19,363 Points

I'm guessing you're stuck with most of it, so I'm going to try to explain it.

  • To create a view first you have to import HttpResponse from django.http
  • Then you would need to create your view by defining a the function which in this case is called index
  • Lastly we simply return a HTTP response that contains the string 'Hello Treehouse'

Like so:

from django.http import HttpResponse

def index(request):
    return HttpResponse('Hello Treehouse')

I'd recommend reading a bit more on it, here's the link that Kenneth provided to help out https://docs.djangoproject.com/en/1.10/topics/http/views/#a-simple-view