Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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