Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python UpdateView的问题_Python_Django_Django Urls - Fatal编程技术网

Python UpdateView的问题

Python UpdateView的问题,python,django,django-urls,Python,Django,Django Urls,我的url定义为: url(r'expand/(?P<pk>[0-9]+)/$', ExpandData.as_view(), name='expand'), 但这给了我以下错误: Reverse for 'expand' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['app/expand/(?P<pk>[0-9]+)/$'] 未找到参数为“()”且关键字

我的url定义为:

url(r'expand/(?P<pk>[0-9]+)/$', ExpandData.as_view(), name='expand'),
但这给了我以下错误:

Reverse for 'expand' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['app/expand/(?P<pk>[0-9]+)/$']
未找到参数为“()”且关键字参数为“{}”的“expand”的反向。尝试了1个模式:['app/expand/(?P[0-9]+)/$'] 在根url加载应用程序时会发生这种情况。我的代码中没有对
reverse('expand')
的调用


为什么会发生这种情况。解决方法是什么?

那么,我的错。我在我的一个模板中有这个:

<li><a href="{% url 'app:expand' %}">{% trans "Expand" %}</a></li>

  • 我想你还需要在
    reverse()中提到
    pk
    作为
    kwargs

    大概是这样的:


    reverse('expand',kwargs={'pk':123})

    完整的错误消息应该给出错误来源的指示。也许您的代码中有
    {%url'展开“%}
    <li><a href="{% url 'app:expand' %}">{% trans "Expand" %}</a></li>