The 'go back' button to cancel a form is not working as indented in Django

I am trying to create a to-do app in Django by following this tutorial. However, things break after creating the ‘go back’ button at 46 minute mark. Clicking go back gives me the following error:

Using the URLconf defined in djangoProject4.urls, Django tried these URL patterns, in this order:

task/<int:pk>/ [name='task']
task-create/ [name='task-create']
The current path, task-create/“/”, didn’t match any of these.

The url is“/” . Which is weird because the code which is suppose to control this link is <a href = “{% url 'tasks' %}”> go back </a>. Clearly this is redirecting to url named ‘tasks’. However it is redirecting to /task-create/"/".

If I change the task in <a href = “{% url 'tasks' %}”> go back </a> to some absurd string. It says NoReverseMatch at /task-create/ and even the home page don’t load.

I am confused, from where is this task-create/"/" coming from? It is certainly not coming from url template.

My template is in root project not the app. To account for that I have changed the I added "DIRS": [BASE_DIR / "templates"], in Templates list.

My code can be found here.

First edit the link commas and quotes retype it make sure it is identical open and close,
i guess it is not. in your code in GitHub you will see the link with different colours.

<a href = "{% url 'todo:tasks' %}"> go back </a>
1 Like

In the source you’re referring to, you have:

<a href = “{% url 'tasks' %}”> go back </a>

Note that you do not have proper quote characters - " surrounding your url tag, you have “fancy quotes” - and .

1 Like

Yup, that solves it. I still don’t understand why would fancy quotes change ‘tasks’ to ‘task-create"/"’.

It’s an issue of how the browser is rendering and interpreting that text. You might want to look at the link that has been created in the HTML in your browser’s developer tools to see exactly what’s being generated.

My conjecture is that task-create is the current url, and the lack of proper quotes is causing the browser to reference that in the absence of a properly quoted value - and then appending the “invalid quoted” reference to tasks to that value.