Difference between revisions of "Using a template."

From MyWiki
Jump to: navigation, search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
Starting with the hello app on line 3 make a modification to the default route:
+
Starting with the hello app on line 3 make a modification to the default route in the views.py file:
 
Replace <source lang="python">
 
Replace <source lang="python">
 
def index(request):
 
def index(request):
 
     return HttpResponse("Hello!") </source>
 
     return HttpResponse("Hello!") </source>
 +
with
 +
<source lang="python">
 +
def index(request):
 +
    return render(request, "hello/index.html")
 +
</source>
 +
Now we need to create the template file in a folder called "templates" in the "hello" folder.<br>
 +
Create the templates folder.<br>
 +
in the templates folder create a folder called "hello" and in it create an index.html file<br>
 +
<source lang="html4strict">
 +
<!DOCTYPE html>
 +
<html lang="eng">
 +
<head>
 +
<title>Hello!</title>
 +
</head>
 +
<body>
 +
<h1> Hello, world!</h1>
 +
</body>
 +
 +
</source>

Latest revision as of 13:37, 19 March 2021

Starting with the hello app on line 3 make a modification to the default route in the views.py file:

Replace
def index(request):
    return HttpResponse("Hello!")

with

def index(request):
    return render(request, "hello/index.html")

Now we need to create the template file in a folder called "templates" in the "hello" folder.
Create the templates folder.
in the templates folder create a folder called "hello" and in it create an index.html file

<!DOCTYPE html>
<html lang="eng">
<head>
<title>Hello!</title>
</head>
<body>
<h1> Hello, world!</h1>
</body>