Skip to content

Commit 69ff77a

Browse files
46 - Include with Arguments
1 parent 0947604 commit 69ff77a

File tree

5 files changed

+23
-28
lines changed

5 files changed

+23
-28
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div class='col-12 col-md-10 mb-3 mx-auto'>
2+
<div class='card'>
3+
<div class='card-body'>
4+
<h5 class='card-title'>{{ blog_post.title }}</h5>
5+
<p class='card-text'>{{ blog_post.content }}</p>
6+
</div>
7+
8+
</div>
9+
</div>

src/blog/templates/blog/list.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33

44
{% block content %}
5-
5+
6+
<div class='row'>
67
{% for object in object_list %}
7-
<li><a href='{{ object.get_absolute_url }}'>{{ object.title }}</a></li>
8+
{% include 'blog/list-inline.html' with blog_post=object %}
89
{% endfor %}
10+
</div>
911

1012

1113
{% endblock %}

src/templates/base.html

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,9 @@
1212
</head>
1313
<body>
1414
{% include 'navbar.html' %}
15-
<div class='container'>
16-
<div class='row'>
17-
<div class='col-6 mx-auto'>
18-
{% block content %}
19-
20-
21-
22-
23-
{% endblock %}
24-
</div>
25-
</div>
15+
<div class='container-fluid'>
16+
{% block content %}
17+
{% endblock %}
2618
</div>
2719

2820
{% include 'js.html' %}

src/templates/home.html

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,12 @@
22

33
{% block content %}
44

5-
{{ title }}
5+
<h1>{{ title }}</h1>
66

7-
{{ request.user }}
87

9-
{{ request.path }}
10-
11-
{{ user }}
12-
13-
{{ user.is_authenticated }}
14-
15-
{% for a in my_list %}
16-
<li>{{ a }} </li>
17-
{% endfor %}
8+
{% for a in blog_list %}
9+
{% include 'blog/list-inline.html' with blog_post=a %}
10+
{% endfor %}
1811

1912

2013

src/try_django/views.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
# Dont Repeat Yourself = DRY
55

66
from .forms import ContactForm
7-
7+
from blog.models import BlogPost
88

99

1010
def home_page(request):
1111
my_title = "Hello there...."
12-
context = {"title": "my title"}
13-
if request.user.is_authenticated:
14-
context = {"title": my_title, "my_list": [1, 2, 3, 4, 5]}
12+
qs = BlogPost.objects.all()[:5]
13+
context = {"title": "Welcome to Try Django", 'blog_list': qs}
1514
return render(request, "home.html", context)
1615

1716

0 commit comments

Comments
 (0)