Difference between revisions of "Extended "Hello world" application to name user"
From MyWiki
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | This is based on the simple "Hello World" application, so we need a working version of it to modify <br> | + | This is based on the simple "Hello World" application(Line 1), so we need a working version of it to modify <br> |
We will add modifications to the hello apps views.py and urls.py files as follows: <br> | We will add modifications to the hello apps views.py and urls.py files as follows: <br> | ||
In the views.py add the following lines: | In the views.py add the following lines: | ||
Line 9: | Line 9: | ||
return HttpResponse("Hello, David!") | return HttpResponse("Hello, David!") | ||
</source> | </source> | ||
− | |||
<br> | <br> | ||
And in the urls.py file add a couple of extra lines | And in the urls.py file add a couple of extra lines | ||
Line 19: | Line 18: | ||
] | ] | ||
</source> | </source> | ||
+ | This enables the urls of /hello/brian and /hello/david to return a personalised greeting |
Latest revision as of 09:58, 19 March 2021
This is based on the simple "Hello World" application(Line 1), 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 views.py add the following lines:
def brian(request): return HttpResponse("Hello, Brian!") def david(request): return HttpResponse("Hello, David!")
And in the urls.py file add a couple of extra lines
urlpatterns = [ path("", views.index, name="index"), path("brian", views.brian, name="brian"), path("david", views.david, name="david") ]
This enables the urls of /hello/brian and /hello/david to return a personalised greeting