'I am taking Cs50 lecture3 Django in which there is a problem that not works the name variable we assigned to each path in urls.py, and create a link

this is my django+html code

   {% extends "tasks/layout.html" %}

   {% block body %}
    
    <h1>Tasks Lists</h1>
    <a href="[% url 'tasks:add' %]"> Add a task</a>
   {% endblock %}

this is where i use varriable name add and link it to another page.

Urls.py

     from django.urls import path
     from . import views


 app_name = "tasks"
 urlpatterns=[
   path("",views.index,name="index"),
   path("add",views.add,name="add")

              ]

this is where i use the varriable name "add".



Solution 1:[1]

A template tag [Django-doc] is written between curly brackets, so It is {%%}, not [%%], you thus write this as:

<a href="{% url 'tasks:add' %}"> Add a task</a>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Willem Van Onsem