Usando o context para enviar dados para dentro dos templates

This commit is contained in:
Luiz Otávio
2023-04-21 11:11:57 -03:00
parent dc90353228
commit 34374a59c7
6 changed files with 27 additions and 7 deletions

View File

@@ -4,7 +4,7 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title> <title>{{ title }}Site do Luiz</title>
<link rel="stylesheet" href="{% static 'home/css/blue.css' %}"> <link rel="stylesheet" href="{% static 'home/css/blue.css' %}">
<link rel="stylesheet" href="{% static 'global/css/red.css' %}"> <link rel="stylesheet" href="{% static 'global/css/red.css' %}">
</head> </head>

View File

@@ -1,3 +1,3 @@
{% extends 'global/base.html' %} {% extends 'global/base.html' %}
{% block texto %} Exemplo {% endblock texto %} {% block texto %} {{ text }} {% endblock texto %}

View File

@@ -1,3 +1,3 @@
{% extends 'global/base.html' %} {% extends 'global/base.html' %}
{% block texto %} Blog {% endblock texto %} {% block texto %} {{ text }} {% endblock texto %}

View File

@@ -4,15 +4,28 @@ from django.shortcuts import render
def blog(request): def blog(request):
print('blog') print('blog')
context = {
'text': 'Olá blog'
}
return render( return render(
request, request,
'blog/index.html' 'blog/index.html',
context
) )
def exemplo(request): def exemplo(request):
print('exemplo') print('exemplo')
context = {
'text': 'Olá exemplo',
'title': 'Essa é uma página de exemplo - ',
}
return render( return render(
request, request,
'blog/exemplo.html' 'blog/exemplo.html',
context
) )

View File

@@ -1,3 +1,5 @@
{% extends 'global/base.html' %} {% extends 'global/base.html' %}
{% block texto %} MUDAR O TEXTO {% endblock texto %} {% block texto %}
{{ text }}
{% endblock texto %}

View File

@@ -4,7 +4,12 @@ from django.shortcuts import render
def home(request): def home(request):
print('home') print('home')
context = {
'text': 'Olá home'
}
return render( return render(
request, request,
'home/index.html' 'home/index.html',
context,
) )