Reverse not found problem

15 views
Skip to first unread message

Metin AKIN

unread,
May 2, 2019, 7:40:20 AM5/2/19
to Django users
Hello, I'm new to django. I have faced with this problem and couldn't find an answer to my problem. I zip 2 lists and I want to iterate them simultaneously.

I get this error
Reverse for '{{newspaper}}' not found. '{{newspaper}}' is not a valid view function or pattern name.


my html file
{% extends "index-template.html" %}

{% block content %}
{% load staticfiles %}
{%
for newspaper, newspaper_name in mylist %}
<li
class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
    <div class="box nop">
        <div class="bar"> <img src="{% static "/icons/{{newspaper}}.png" %}".......
{% endfor %}
{% endblock %}




my index fuction in views.py
def index(request):
    newspapers = [
"BBC", "Guardian"]

    newspaper_names = [
"BBC News", "The Guardian"]
    mylist = zip(newspapers, newspaper_names)

   
return render(request, "index.html", {"currentdate": getcurrentdate(), "mylist": mylist})

Nelson Varela

unread,
May 2, 2019, 9:44:54 AM5/2/19
to Django users
I think you can not render variable in a template tag, so:

{% static "/icons/{{newspaper}}.png" %}

maybe should be

{% static "/icons/" %}{{newspaper}}.png


Andréas Kühne

unread,
May 3, 2019, 7:35:32 AM5/3/19
to django...@googlegroups.com
This doesn't make sense at all - if you want a variable in the static call you need to do something like this:

{% with 'icons/'|add:newspaper|add:'.png' as image_static %}
  {% static image_static %}
{% endwith %}
The reason for not just adding it to the end is because you could have md5 hashes in your static file as well. So therefore this is the best way to do it.

Regards,

Andréas


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4f2a0b3a-ab7c-46b2-8fdd-020c2bf8fd2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages