Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Invalind linking throws 'id' expected a number but got '{{ navbarList.0.category }}'

I have probably a very simple error but I can’t figure it out.

I have a category model that looks like this. Navbar field is for putting the category name and link to it in the navbar section on the page.

class Category(models.Model):
    category = models.CharField(max_length=20,unique=True)
    navbar = models.BooleanField(null=False, blank=False, default=True)

    def __str__(self):
        return self.category

Due to menu layout looking like this I need to set nav links manually

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

nav - nav - language_changer - nav - nav\

So I’ve set them like this

<a href='{% url "category" category="{navbarList.0.id }" %}'>
  {{ navbarList.0.category }}
</a>
<a href='{% url "category" category="{navbarList.1.id }" %}'>
  {{ navbarList.1.category }}
</a>

And this throws error

ValueError at /category/{{ navbarList.0.id }}/
Field 'id' expected a number but got '{{ navbarList.0.id }}'.

>Solution :

You should not wrap variables included in tags with braces, remove them and reference the variable without any wrapper

<a href='{% url "category" category=navbarList.0.id %}'>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading