0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Django】TemplateSyntaxErrorが出た

Posted at

DjangoGirlsの練習で、post_detailを実装している際に以下のエラーに遭遇した。
結論、原因はhrefのurl指定で {% tag %}を使用すべき箇所に{{ var }}を使用していたことであった。

TemplateSyntaxError at /
Could not parse the remainder: ' 'post_detail' pk=post.pk' from 'url 'post_detail' pk=post.pk'

{% extends 'blog/base.html' %}
{% block content %}
  {% for post in posts %}
    <div>
      <h2>
        <a href="{{ url 'post_detail' pk=post.pk }}">{{ post.title }}</a>
      </h2>
      {% if post.published_date %}<p>{{ post.published_date }}</p>{% endif %}
      <p>by {{ post.author }}</p>
      <p>{{ post.text }}</p>
    </div>
  {% endfor %}
{% endblock %}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?