Now that you have the routes linked with the project, you can start displaying messages on a web page.
For example, edit the articles\views.py
file like this to return the corresponding HttpResponse
.
from django.shortcuts import render, HttpResponse
# Create your views here.
def welcome(request):
return HttpResponse("<h1>Welcome to Edkool!!</h1>")
This view function needs to be connected to a route in the urls.py
file which can be done accordingly.
Open the articles\urls.py
file and make the following change:
from . import views
urlpatterns = [
path("", views.welcome, name='welcome'),
]
The first argument passed to the path function is the path
of the route, that is when it should get called and the second argument is the function
to be called when that particular route is visited, followed by an optional parameter name
that can be useful while redirecting to a specific page.
After these changes, when you visit http://127.0.0.1:8000/articles/, you will be able to see a page like this: And there you go, congratulations on displaying a message on the web page. This is just a start, further you can modify the web page to display the content that you want.