45 - Django URLs Reverse - Python & Django 3.2 Tutorial Series

preview_player
Показать описание
45 - Django URLs Reverse - Python & Django 3.2 Tutorial Series

Try Django 3.2 is a series to teach you the fundamentals of creating web applications with Python & Django by building a real project step-by-step.

Рекомендации по теме
Комментарии
Автор

Just wanted to add this for more content in Django Templates:

1. In HTML even if lines are commented out Django still tries to process template tag:

Example:
<!-- <a href='{% url "article-detail" slug=x.slug %}'>detail Article</a> -->

Django still tries to process the {% url %} template tag and the x.slug variable within it. If x.slug is not defined or has an empty value, it can lead to errors when Django tries to render the template.

In this case, completely removing the commented lines resolved the issue because Django no longer attempts to process the problematic code within the commented block.

To prevent Django from attempting to process code within a commented block, you can use Django template comment syntax {% comment %} and {% endcomment %} instead of HTML comments. This ensures that everything within the {% comment %} block is completely ignored by Django during template rendering. For example:

{% comment %}
<a href='{% url "article-detail" slug=x.slug %}'>detail Article</a>
{% endcomment %}

Using Django template comments provides a clearer indication that the enclosed code should not be processed by Django during template rendering.

batman_
Автор

From here I can grab a way to redirect New urls.

ashir
Автор

I used return redirect ("view name") in views.py under a function
but upon calling the endpoint it gives me a response like this
function xyz at 01x214, some memory location.

RishabhSingh-oiyf