找不到“surveydetails”的反向项surveydetails'不是有效的视图函数或模式名称

2024-04-19 20:09:52 发布

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

我在这个问题上纠缠了一段时间,似乎无法修复错误。我已经检查了代码一百次了,但是很明显我遗漏了一些东西。我也安装了我的应用程序

有人能看到我遗漏了什么吗

视图.py

 def survey_details(request, id=None):
     context = {}
     surveys = Survey.objects.get(id=id)
     context['survey'] = survey
     return render(request, 'surveydetails.html', context)

feedback.url.py

path('details/<int:id>', views.survey_details, name="surveydetails"),

surveys.html

{% extends 'main.html' %}

{% block content%}

    <h1>Surveys</h1>
    <h2>list of {{title}} </h2>
    {% if surveys %}
        <ul>
            {% for survey in surveys %}
            <li>
                <a href="{% url 'feedback:surveydetails' %}">{{ survey.title }}</a>
            </li>
            {% endfor %}
        </ul>
    {% else %}
        <p>There are no surveys.</p>
    {% endif %}
{% endblock %}

surveydetails.html

{% extends 'main.html' %}

{% block content%}

    <h1>Surveys</h1>
    <h2>Detail page</h2>
    <h3>{{question.title}}</h3>
    <p>Details page of {{question.title}}</p>

{% endblock %}