Im trying to make a wikipedia clone for studying purposes, ‘encyclopedia’ is my django app name and {{entry}} its a wiki page. My code line looks like this : <a href="{% url 'encyclopedia:{{entry}}'%}"
>,
I searched in google but cant find anyone talking about django variables inside HTML tag atributtes.
When I run my code i see this error:
`NoReverseMatch at /
Reverse for '{{entry}}' not found. '{{entry}}' is not a valid view function or pattern name. `
2
Answers
The issue you’re facing is because you’re using Django template variables inside the {% url %} template tag incorrectly. In Django templates, you don’t need to use double curly braces ({{ }}) inside the {% url %} tag.
Here’s how you should structure your link:
You cannot directly use Django template variables inside the {% url %} template tag. Instead, you need to pass the variable as an argument to the template tag itself. Here’s the corrected code:
Make sure that the entry variable is properly defined and passed to the template context from the view for this code to work correctly.