01 Start with a project
Use the project from the installation tutorial. Make sure core appears in INSTALLED_APPS. A view receives an HTTP request and returns an HTTP response.
02 Write a view
Replace the contents of core/views.py with a small function. HttpResponse is useful when you only need to return a short piece of text.
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello, Django!")03 Connect the URL
In config/urls.py, connect the empty path to home. The empty string represents the homepage, and the name lets other parts of the application refer to this route without hardcoding its address.
from django.contrib import admin
from django.urls import path
from core.views import home
urlpatterns = [
path("", home, name="home"),
path("admin/", admin.site.urls),
]04 Try the request
Start the development server and open the homepage. You should see Hello, Django! Change the message and refresh the browser to see your edit. Next, move the HTML into a template.
python manage.py runserver
# In another terminal:
curl http://127.0.0.1:8000/Read the official Django documentation for details and more examples.