About Lesson
Basic Function-Based View
-
- Define a view in
views.py
:
from django.http import HttpResponse def index(request): return HttpResponse("Welcome to My App!")
- Define a view in
- Connect the view to a URL pattern:
-
- Update
myapp/urls.py:
- Update
urlpatterns = [ path('', views.index, name='index'), ]
-
Rendering HTML Content
Instead of returning plain text, render HTML templates for dynamic content:
from django.shortcuts import render
def index(request):
return render(request, 'myapp/index.html')
Join the conversation