模板呈现期间出现Django错误。找不到参数为“(”,)”和关键字参数“{}”的“name”的反向操作

2024-05-16 18:08:33 发布

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

我正在做我的第一个Django项目,现在我有一些我根本不明白的错误!昨天,我把其中一个表格的数据保存到了第二个表格中。我试图解决这个问题,但现在两个都不起作用,我甚至有一个旧模板有同样的问题。你能告诉我我的错误是什么,我怎样才能改正它们吗?在

这是我的一部分视图.py公司名称:

def listing(request):
    users_list = Person.objects.all()
    paginator = Paginator(users_list, 14) 
    page = request.GET.get('page')
    try:
        users = paginator.page(page)
    except PageNotAnInteger:
        users = paginator.page(1)
    except EmptyPage:
        users = paginator.page(paginator.num_pages)
    return render(request, 'friends_plans/list.html', {"users": users})

def add_wish_list(request):
    if request.method == 'POST':
        form = Wish_listForm(request.POST)
        if form.is_valid():
            newform = form.save(commit=False)
            newform.person = request.user
            newform.save()
        else:
            print form.errors
    else:
        form = Wish_listForm()
    return render(request, 'friends_plans/add_wish_list.html', {'form': form})

def add_comment(request, wish_list_id):
    person = request.user
    wish_list = get_object_or_404(Wish_list, pk=wish_list_id)
    if request.method == 'POST':
        form = Comment_to_wish_listForm(request.POST)
        if form.is_valid():
            newform=form.save(commit=False)
            newform.person = request.user
            newform.comment_to = wish_list
            wish_list.person = person
            newform.save()
        else:
            print form.errors
    else:
        form = Comment_to_wish_listForm()
    context_dict = {'form': form, 'wish_list': wish_list}
    return render(request, 'friends_plans/add_comment.html', {'context_dict':  context_dict})

这是我的网址.py公司名称:

^{pr2}$

这是列表.html公司名称:

{% extends 'friends_plans/base.html' %}
{% load staticfiles %}
    {% block title %} Users {% endblock %}
    {% block content %}
        <div id ="left">
            <div id="toptitle"> Friends' Plans members:</div>
            <table class="table">
                    <thead>
                      <tr>
                        <th>Photo</th>
                        <th>Name</th>
                        <th>Occupation</th>
                        <th>Days</th>
                        <th>Places</th>
                      </tr>
                    </thead>
                    <tbody>
                    {% for person in users %}
                      <tr>
                        <td><span> <img class="small_cat" src={% static  'images/cat3.jpg' %} /> </span></td>
                        <td><a href="{% url 'friends_plans:user' user.pk  %}">{{ person.username|upper }}</a></span></td>
                        <td><span>Student at {{   person.place_of_work_or_study}}</span></td>
                        <td>{{person.day_set.all.count}}</td>
                        <td>{{person.wish_list_set.all.count}}</td>
                      </tr>
                    {% endfor %}
                    </tbody>
                  </table>
            <div class="pagination">
                <div id="listing">
                    <span class="step-links">
                        {% if users.has_previous %}
                            <a href="?page={{ users.previous_page_number  }}">previous</a>
                        {% endif %}

                        <span class="current">
                            Page {{ users.number }} of {{  users.paginator.num_pages }}.
                        </span>

                        {% if users.has_next %}
                            <a href="?page={{ users.next_page_number  }}">next</a>
                        {% endif %}
                    </span>
                </div>
            </div>
        </div>
    {% endblock %}

这是add\u wish_列表.html公司名称:

{% extends 'friends_plans/base.html' %}
{% load staticfiles %}
{% block content %}
<h1>Add a wish_list</h1>
<form method="post"  action="/friends_plans:add_wish_list/">
    {% csrf_token %}
    {{form.as_p}}
    <input type="submit" value="Add wish_list" />
</form>
{% endblock %}

这是add_评论.html公司名称:

{% extends 'friends_plans/base.html' %}
{% block content %}

<h1>Add a wish_list</h1>
<form method="post"  action="">
    {% csrf_token %}
    {{form.as_p}}
    <input type="submit" value="Add comment" />
</form>
{% endblock %}

我知道这个问题与网址有关,但我不明白它是什么,为什么一切都很好列表.html因为我没有改变它!在


Tags: divformaddrequesthtmlpageuserslist