Django模板呈现期间出错

2024-04-26 15:00:17 发布

您现在位置:Python中文网/ 问答频道 /正文

在django教程中工作时,会出现模板呈现中的此错误

NoReverseMatch at /music/1/ Reverse for 'favorite' with arguments '(1,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

这是问题的详细视图

Error during template rendering
In template E:\Codes\bucky - Django Tutorials for Beginners\website\music\templates\music\detail.html, error at line 10
Reverse for 'favorite' with arguments '(1,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

1   <img src="{{ album.album_logo }}">
2   
3   <h1>{{ album.album_title }}</h1>
4   <h2>{{ album.artist }}</h2>
5   
6   {% if error_message %}
7       <p><strong>{{ error_message }}</strong></p>
8   {% endif %}
9   
10  <form action="{% url 'music:favorite' album.id %}" method="post">
11      {% csrf_token %}

这是我的音乐/网址.py在

^{pr2}$

在详细信息.html表单中出现错误的文件

<img src="{{ album.album_logo }}">

<h1>{{ album.album_title }}</h1>
<h2>{{ album.artist }}</h2>

{% if error_message %}
    <p><strong>{{ error_message }}</strong></p>
{% endif %}

<form action="{% url 'music:favorite' album.id %}" method="post">
    {% csrf_token %}
    {% for song in album.song_set.all %}
        <input type="radio" id="song{{ forloop.counter }}" name="song" value="{{ song.id }}">
        <label for="song{{ forloop.counter }}">
            {{ song.song_title }}

            {% if song.is_favorite %}
                <img src="http://i.imgur.com/b9b13Rd.png">
            {% endif %}
        </label>
        <br>
    {% endfor %}

    <input type="submit" value="Favorite">
</form>

Tags: srcidmessageimgforalbumsongtitle