Difference between revisions of "Using a template with parameters."
From MyWiki
(Created page with "Let us modify the views.py from the hello app on line 3<br>") |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Let us modify the views.py from the hello app on line 3<br> | Let us modify the views.py from the hello app on line 3<br> | ||
+ | In the hellos application views.py file edit the greet function to look like below: | ||
+ | <source lang="python"> | ||
+ | def greet(request, name): | ||
+ | return render(request, "hello/greet.html", { | ||
+ | "name": name.capitalize() | ||
+ | }) | ||
+ | |||
+ | </source> | ||
+ | Now create a greet.html file in the templates/hello folder <br> | ||
+ | <source lang="html4strict"> | ||
+ | <!DOCTYPE html> | ||
+ | <html lang="en"> | ||
+ | <head> | ||
+ | <title> Hello</title> | ||
+ | </head> | ||
+ | |||
+ | <body> | ||
+ | <h1> Hello, {{ name }}!</h1> | ||
+ | </body> | ||
+ | </html> | ||
+ | |||
+ | </source> |
Latest revision as of 16:54, 19 March 2021
Let us modify the views.py from the hello app on line 3
In the hellos application views.py file edit the greet function to look like below:
def greet(request, name): return render(request, "hello/greet.html", { "name": name.capitalize() })
Now create a greet.html file in the templates/hello folder
<!DOCTYPE html> <html lang="en"> <head> <title> Hello</title> </head> <body> <h1> Hello, {{ name }}!</h1> </body> </html>