Extended "Hello world" application to name user an accept any name

From MyWiki
Jump to: navigation, search

This is based on the simple "Hello World" application(Line 2), so we need a working version of it to modify
We will add modifications to the hello apps views.py and urls.py files as follows:
In the urls.py in the hello folder add a line:

path("<str:name>", view.greet, name="greet"),

so that the urls.py file urlpatterns section now looks like:

from django.urls import path
from . import views
urlpatterns={
             path("", views.index, name="index"),
             path("<str:name>", views.greet, name="greet"),
             path("brian", views.brian, name="brian"),
             path("david", views.david, name="david")
            }

Now add the following to the end of the views.py file in the hello directory:

def greet(request, name):
     return HttpResponse("Hello, {name.capitalize()}")