Hello, Django
Part of the Django Basics section of Coddy's Django journey. Lesson 1 of 23.
Corner Café has a new website, and its home page still shows a placeholder.
Your browser asks a server for a page: that is a request. The server sends the page back: the response. Django is a Python framework for writing that server. This function in menu/views.py sends back the home page:
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello from Django!")A function like this is a view. Django calls it when a request arrives, and the text in the HttpResponse it returns is the page.
Run starts the site beside your code, like python manage.py runserver on a laptop. Check tests the code in the editor and tells you whether the lesson is done.
Challenge
EasyIn menu/views.py, change the text in home from Hello from Django! to Welcome to Corner Café.
Press Run to see it, then Check.
Try it yourself
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello from Django!")
All lessons in Django Basics
Practice on your own: Django playground