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

Django: is not a valid view function or pattern name when trying to add a url using url tag in django

i want to add a url to my project that would get the id of a video and append it to url like this http://127.0.0.1:8000/course/learn-angular/contents/?lecture=1 <a href="?lecture={{v.serial_number}}" instead of the regular django {% url '?lecture={{v.serial_number}}' %}.

when i do this <a href="{% url '?lecture={{v.serial_number}}' %}"> that is when i get this error Reverse for '?lecture={{v.serial_number}}' not found. '?lecture={{v.serial_number}}' is not a valid view function or pattern name..

NOTE: when i add the url as ?lecture={{v.serial_number}} is show this error when i click on the url Page not found (404) Directory indexes are not allowed here and all these are happening i think becuase i have this line <base href="{% static '/' %}"> in my base.html where i am extending all my static files from.

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

And if you asking why i have this line base href="{% static '/' %}">, it’s becuase my static files are not loading up as usual, it keep showing a MIME type not supoorted error, refused to apply 127.0.0.1:8000/assets/css/style.css so the only way i could fix this was to add that line to my base.html.

Back to the main question, what is the right way to write tihs url withot getting this error Page not found (404) Directory indexes are not allowed here.

>Solution :

You need to pass in the url name for the urlpattern that matches /course/learn-angular/contents/ and then pass in the query params for the lecture id ?lecture=1

<a href="{% url 'name_for_route' %}?lecture={{v.serial_number}}">
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