NoReverseMatch:关键字参数未传递

用户名

我遇到以下错误,我无法终生弄清楚问题出在哪里,我已将所有内容从“ site”重命名为“ place”,以确保名称与除尽管我可以在URL和错误页面的交互式视图中以u'7'的形式看到它,但place_id仍未传递。

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8080/afp/sites/update/4/

Django Version: 1.6.2
Python Version: 2.7.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.gis',
 'compressor',
 'django_extensions',
 'floppyforms',
 'crispy_forms',
 'djcelery',
 'kombu.transport.django',
 'mptt',
 'south',
 'tastypie',
 'django_nose',
 'selectable',
 'rapidsms',
 'rapidsms.router.db',
 'rapidsms.contrib.handlers',
 'rapidsms.contrib.messagelog',
 'rapidsms_telerivet',
 'phis.nomads',
 'phis.core',
 'phis.afp',
 'phis.messagebox']
Installed Middleware:
('django.middleware.cache.UpdateCacheMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.cache.FetchFromCacheMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Template error:
In template /home/dan/workspace/phis-polio/eha-phis/phis/afp/templates/sites-update.html, error at line 10
   Reverse for 'sites-update' with arguments '()' and keyword arguments '{u'place_id': ''}' not found. 1 pattern(s) tried: ['afp/sites/update/(?P<place_id>[-\\d]+)/$']
   1 : {% extends "newbase.html" %}


   2 : {% load url from future %}


   3 : {% load floppyforms %}


   4 : {% load staticfiles %}


   5 : {% block title %} - Update Site {% endblock %}


   6 : {% block content %}


   7 : <div class="row">


   8 : <div class="col-sm-6 col-md-6">


   9 :     <h3 class="heading">Update Surveillance Site</h3>


   10 :     <form method="post" action= {% url 'sites-update' place_id=site.pk %} >


   11 :         {% csrf_token %}


   12 :         <div class="formSep">


   13 :             <div class="row">


   14 :                 <div class="col-sm6 col-md-6">


   15 :                 <label for="id_name">Site Name:<span class="f_req">*</span></label>


   16 :                     {{ form.name }}


   17 :                 <span class="help-block">What is the site name?</span>


   18 :                 </div>


   19 :                 <div class="col-sm-6 col-md-6">


   20 :                     <label for="id_lga">LGA:<span class="f_req">*</span></label>


Traceback:
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  22.                 return view_func(request, *args, **kwargs)
File "/home/dan/workspace/phis-polio/eha-phis/phis/afp/views.py" in sites_update_view
  91.         'place_id': place_id
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/shortcuts/__init__.py" in render
  53.     return HttpResponse(loader.render_to_string(*args, **kwargs),
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  169.         return t.render(context_instance)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/base.py" in render
  140.             return self._render(context)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/base.py" in render
  840.                 bit = self.render_node(node, context)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  78.             return node.render(context)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  123.         return compiled_parent._render(context)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/base.py" in render
  840.                 bit = self.render_node(node, context)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  78.             return node.render(context)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  62.             result = block.nodelist.render(context)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/base.py" in render
  840.                 bit = self.render_node(node, context)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  78.             return node.render(context)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  447.                         six.reraise(*exc_info)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  433.             url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse
  509.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/home/dan/workspace/phis-polio/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
  429.                              (lookup_view_s, args, kwargs, len(patterns), patterns))

Exception Type: NoReverseMatch at /afp/sites/update/4/
Exception Value: Reverse for 'sites-update' with arguments '()' and keyword arguments '{u'place_id': ''}' not found. 1 pattern(s) tried: ['afp/sites/update/(?P<place_id>[-\\d]+)/$']

这是我的模板代码:

{% extends "newbase.html" %}
{% load url from future %}
{% load floppyforms %}
{% load staticfiles %}
{% block title %} - Update Site {% endblock %}
{% block content %}
<div class="row">
<div class="col-sm-6 col-md-6">
    <h3 class="heading">Update Surveillance Site</h3>
    <form method="post" action={% url 'sites-update' place_id=site.id %}>
        {% csrf_token %}
        <div class="formSep">
            <div class="row">
                <div class="col-sm6 col-md-6">
                <label for="id_name">Site Name:<span class="f_req">*</span></label>
                    {{ form.name }}
                <span class="help-block">What is the site name?</span>
                </div>
                <div class="col-sm-6 col-md-6">
                    <label for="id_lga">LGA:<span class="f_req">*</span></label>
                    {{ form.lga }}
                <span class="help-block">What is the LGA?</span>
                </div>
                <div class="col-sm-6 col-md-6">
                    <label for="id_site_type">Site Type:<span class="f_req">*</span></label>
                    {{ form.site_type }}
                <span class="help-block">What type of site is this?</span>
                </div>
                <div class="col-sm-6 col-md-6">
                    <label for="id_site_priority">Site Priority:<span class="f_req">*</span></label>
                    {{ form.site_priority }}
                <span class="help-block">What is the priority of this site?</span>
                </div>
                <div class="col-sm-6 col-md-6">
                    <label for="id_site_category">Site Category:<span class="f_req">*</span></label>
                    {{ form.site_category }}
                <span class="help-block">What category should the site be in?</span>
                </div>
            </div>
        </div>
        <div class="row">
            <input class="btn btn-default" type="submit" value="Save" />
            <a class="btn btn-default" href={% url "sites-index" %}>Cancel</a>
        </div>
    </form>
</div>
</div>
{{ form.errors }}
{% endblock %}
{% block sidebar %}
    {% include "afp-sidebar.html" %}
{% endblock %}

我的观点:

@login_required
def sites_update_view(request, place_id=None):
    if place_id:
        site = get_object_or_404(SiteMeta, pk=place_id)
    else:
        return redirect('sites-index')

    if request.GET:
        form = SitesAddForm(instance=site)

    if request.POST:
        form = SitesAddForm(request.POST, instance=site)
        if form.is_valid():
            form.save()
            return redirect('sites-index')
    else:
        form = SitesAddForm()

    return render(request, 'sites-update.html', {
        'form': form,
        'place_id': place_id
    })

我的网址:

#!/usr/bin/env python
# encoding=utf-8

# afp.urls

from django.conf.urls import patterns, url
from .views import (afp_index_view, personnel_index_view, sites_index_view, afp_messaging_view, afp_weekly_create_view,
                    case_report_create_view, weekly_reports_list, case_report_list, personnel_add_view, sites_add_view,
                    afp_nonreporting_site_list, sites_update_view)

urlpatterns = patterns('',
    # ex: /afp/
    url(r'^$', afp_index_view, name='afp-index'),
    url(r'^personnel/$', personnel_index_view, name='personnel-index'),
    url(r'^personnel/add/$', personnel_add_view, name='personnel-add'),
    url(r'^sites/$', sites_index_view, name='sites-index'),
    url(r'^sites/add/$', sites_add_view, name='sites-add'),
    url(r'^sites/update/(?P<place_id>[-\d]+)/$', sites_update_view, name='sites-update'),
    url(r'^afp-messaging/$', afp_messaging_view, name='afp-messaging'),
    url(r'^weekly-reports-list', weekly_reports_list, name='weekly-reports-list'),
    url(r'^weekly/add/$', afp_weekly_create_view, name="afp-weekly-add"),
    url(r'^weekly/add/(?P<msgid>[-\d]+)/$', afp_weekly_create_view, name="afp-weekly-add-from-msg"),
    url(r'^case-report/add/(?P<msgid>[-\d]+)/$', case_report_create_view, name='case-report-add-from-msg'),
    url(r'^case-report-list', case_report_list, name='case-report-list'),
    url(r'^sites-not-reporting/$', afp_nonreporting_site_list, name='afp-sites-not-reporting'),
    )
丹尼尔·罗斯曼

模板中触发错误的行包括:

{% url 'sites-update' place_id=site.id %}

但是您没有将任何调用传递"site"给模板:onlyformplace_id您可以place_id直接使用,但是您可能还是希望将网站传递给模板。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

关键字参数匹配时找不到带有关键字参数的NoReverseMatch

来自分类Dev

关键字未传递功能

来自分类Dev

NoReverseMatch异常-使用关键字参数进行重定向

来自分类Dev

将未初始化的参数传递给方法时的ref关键字

来自分类Dev

将哈希传递给接受关键字参数的函数

来自分类Dev

如何确定传递的关键字参数的顺序?

来自分类Dev

如果条件为真,则传递关键字参数

来自分类Dev

Django NoReverseMatch错误找不到带有参数'('',)'和关键字参数'{}'的'detail'的反向

来自分类Dev

传递带有包含关键字字符串的变量的关键字参数

来自分类Dev

递归传递关键字

来自分类Dev

Ruby关键字参数

来自分类Dev

无关键字参数

来自分类Dev

关键字和非关键字参数的顺序

来自分类Dev

Django-NoReverseMatch。找不到带有参数'(2,)'和关键字参数'{}'的''。尝试了0个模式:[]

来自分类Dev

找不到与参数'()'和关键字参数'{}'的'password_change_done'反向匹配的NoReverseMatch。尝试了0个模式:[]

来自分类Dev

Common Lisp:如果已经传递给我,如何传递关键字参数

来自分类Dev

如何将关键字作为可以传递给 update-in 的参数传递?

来自分类Dev

将关键字参数作为必需参数传递给Python

来自分类Dev

具有关键字参数的Python动态函数避免使用未使用的参数

来自分类Dev

django-rest-framework:不能调用`.is_valid()`,因为在实例化序列化程序实例时未传递`data =`关键字参数

来自分类Dev

在Swift中传递关键字

来自分类Dev

使用ref关键字传递值

来自分类Dev

方案关键字未绑定

来自分类Dev

方案关键字未绑定

来自分类Dev

TSLint:未使用的var关键字

来自分类Dev

Swift参数中的默认关键字

来自分类Dev

Asyncio中的请求-关键字参数

来自分类Dev

matplotlib radviz中的关键字参数

来自分类Dev

python类关键字参数

Related 相关文章

  1. 1

    关键字参数匹配时找不到带有关键字参数的NoReverseMatch

  2. 2

    关键字未传递功能

  3. 3

    NoReverseMatch异常-使用关键字参数进行重定向

  4. 4

    将未初始化的参数传递给方法时的ref关键字

  5. 5

    将哈希传递给接受关键字参数的函数

  6. 6

    如何确定传递的关键字参数的顺序?

  7. 7

    如果条件为真,则传递关键字参数

  8. 8

    Django NoReverseMatch错误找不到带有参数'('',)'和关键字参数'{}'的'detail'的反向

  9. 9

    传递带有包含关键字字符串的变量的关键字参数

  10. 10

    递归传递关键字

  11. 11

    Ruby关键字参数

  12. 12

    无关键字参数

  13. 13

    关键字和非关键字参数的顺序

  14. 14

    Django-NoReverseMatch。找不到带有参数'(2,)'和关键字参数'{}'的''。尝试了0个模式:[]

  15. 15

    找不到与参数'()'和关键字参数'{}'的'password_change_done'反向匹配的NoReverseMatch。尝试了0个模式:[]

  16. 16

    Common Lisp:如果已经传递给我,如何传递关键字参数

  17. 17

    如何将关键字作为可以传递给 update-in 的参数传递?

  18. 18

    将关键字参数作为必需参数传递给Python

  19. 19

    具有关键字参数的Python动态函数避免使用未使用的参数

  20. 20

    django-rest-framework:不能调用`.is_valid()`,因为在实例化序列化程序实例时未传递`data =`关键字参数

  21. 21

    在Swift中传递关键字

  22. 22

    使用ref关键字传递值

  23. 23

    方案关键字未绑定

  24. 24

    方案关键字未绑定

  25. 25

    TSLint:未使用的var关键字

  26. 26

    Swift参数中的默认关键字

  27. 27

    Asyncio中的请求-关键字参数

  28. 28

    matplotlib radviz中的关键字参数

  29. 29

    python类关键字参数

热门标签

归档