Skip to content

Commit 9709b1c

Browse files
committed
Fix template image handling for posts without images
1 parent 9788225 commit 9709b1c

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

portfolio/templates/portfolio/home.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ <h2>My Spiel</h2>
2929
<p>
3030
I'm a software engineer with a passion for building things. I'm a Full Stack Decentralized Application Developer with various interests and skils not limited to Distributed Development, Data Science, Artificial Inteligence and Machine Learning. I enjoy building things from the ground up and learning new things. I'm an experienced developer and I'm always looking for new opportunities to learn and grow through self-learning and contributing to opensource software and various stack exchange forums. I participate actively on programming platforms, <a href='https://www.leetcode.com/ericgitangu'>LeetCode</a>, TopCoder, <a href='https://www.hackerrank.com/theace'>Hackerrank</a> and <a href='https://www.codingame.com/profile/e5d13e7fbe4b82eb26c601fd545bf8af1580081'>CodingGames </a>
3131
</p>
32-
</section
32+
</section>
3333

34-
{%endblock%}
34+
{% endblock %}

portfolio/templates/portfolio/includes/post_slug.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
<li>
44
<article class="post">
5-
<a href= {%url 'post_detail' post.slug%}>
5+
<a href="{% url 'post_detail' post.slug %}">
6+
{% if post.image %}
67
<img src="{{ post.image.url }}" alt="post image">
8+
{% else %}
9+
<img src="{% static 'avatar.jpg' %}" alt="default image">
10+
{% endif %}
711
<div class="post__content">
8-
<h3>{{ post.title}}</h3>
9-
<p>{{ post.excerpt}}</p>
12+
<h3>{{ post.title }}</h3>
13+
<p>{{ post.excerpt }}</p>
1014
</div>
1115
</a>
1216
</article>

portfolio/templates/portfolio/post_details.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ <h2>{{post.title}}</h2>
4747
</form>
4848
</div>
4949
<article>
50-
<img src="{{ post.image.url }}" alt={{ post.title}}/>
50+
{% if post.image %}
51+
<img src="{{ post.image.url }}" alt="{{ post.title }}"/>
52+
{% else %}
53+
<img src="{% static 'avatar.jpg' %}" alt="{{ post.title }}"/>
54+
{% endif %}
5155
<address>
5256
<p>Written by <a href="mailto:{{post.author.email}}">{{post.author}}</a></p>
5357
<p>Published on {{post.date|date:'D, d M Y H'}}</p>

0 commit comments

Comments
 (0)