Nicolas_Darksoul
Nicolas_Darksoul

Reputation: 79

how can i avoid no reverse match in django

I don't know why this error occurred no revers match while I'm practicing Django.

I modified the shops.html code to link pizza but after this modifying, this error occurred

Reverse for 'pizza' with arguments '('',)' not found. 1 pattern(s) tried: ['shops/(?P<pizza_id>[0-9]+)$']

first code :

<ul>
    {%for shop in shops%}

         <li>
            {{shop}}
         </li>

second code:

<ul>
    {%for shop in shops%}

     <li>
        <a href="{% url 'pizzas:pizza' pizza.id %}">{{shop}}</a></li>

I have Posted all codes in Pastebin if needed.

Upvotes: 0

Views: 42

Answers (1)

Thierno Amadou Sow
Thierno Amadou Sow

Reputation: 2573

your problem is that instead of shop.pk you used pizza.id and that is not actually defined.
change this

{%for shop in shops%}
 
 <li>
    <a href="{% url 'pizzas:pizza' pizza.id %}">{{shop}}</a></li>
 
{%empty%}
 
 <li>currently there is no pizza available</li>
{%endfor%}

to

{%for shop in shops%}
 
 <li>
    <a href="{% url 'pizzas:pizza' shop.pk %}">{{shop}}</a></li>
 
{%empty%}
 
 <li>currently there is no pizza available</li>
{%endfor%}

Upvotes: 1

Related Questions