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 Django倒车给我带来了一些麻烦_Python_Django - Fatal编程技术网

Python Django倒车给我带来了一些麻烦

Python Django倒车给我带来了一些麻烦,python,django,Python,Django,我的问题是,当调用reverse时,它抛出以下异常 找不到参数为“(3,)”且关键字参数为“{}”的“/documentation/”的反转。已尝试0个模式:[] 这是我的URL.py url(r'^documentation/$', views.view1), url(r'^documentation/([0-9])/$', views.documents, name='documentation'), 这是我的观点 def view1(request): if request.met

我的问题是,当调用reverse时,它抛出以下异常

找不到参数为“(3,)”且关键字参数为“{}”的“/documentation/”的反转。已尝试0个模式:[]

这是我的URL.py

url(r'^documentation/$', views.view1),
url(r'^documentation/([0-9])/$', views.documents, name='documentation'),
这是我的观点

def view1(request):

  if request.method == 'POST':
      profe = request.POST.get('value')

      a = value.encode('ascii', 'ignore')
      b = int(a)
      return HttpResponseRedirect(reverse('documentation', args=(b,)))

else:

    return render(request, "documentation.html", info)

def documents(request,valor):
      ...something...
      return render(request, "anotherdoc.html", ..something..)
这是我的模板(documentation.html)


Reverse使用URL名称,您将名称声明为
name='documentation'
,但我们可以看到您使用的是
'/documentation/'

File "C:\Users\Pa\Desktop\Nueva carpeta\ag\Ag\scheduler\views.py" in documentation
  82.         url = reverse('/documentation/', args=(3,))
将该行更改为
url=reverse('documentation',args=(3,)


如果您的URL以名称间隔(如果您有另一个URL.py,其中包含此URL(),您就会知道这一点),您应该使用
'[名称空间]:documentation'

它看起来是正确的。你应该试着把你的例子简化成一个简单的例子,以便这里的人进行进一步的调查。顺便说一句,欢迎使用SO。错误表明它按名称
/documentation/
查找视图,而不是
documentation
(请注意斜线)。请提供完整的回溯和回溯中提到的相关代码。谢谢你们两位的回答,我刚刚用回溯编辑了我的问题是你的根URL.py还是应用程序中的子URL.py?@AntoineFontaine是应用程序的URL.py,谢谢你的回答。这句话的原意和你描述的一样(现在又是这样了,我和我在问题中描述的那句话是一样的)。当我复制回溯时,我正在改变一些事情,试图让reverse()工作。不幸的是没有success@kamus_pc您将需要提供与当前故障状态相关的回溯,如果不是该状态,因为你所发布的错误在这一行中非常有意义——也许其他地方也有同样的错误。只是添加了正确的回溯,并添加了我在视图中的另一个视图。py可能存在冲突。解释否决票?鉴于所提供的信息,这是唯一可行的解决方案。这不是我给出的,我非常感谢您抽出时间回答我的问题。
Traceback:

File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\Pa\De\Nueva carpeta\ag\Ag\scheduler\views.py" in documentation
  82.         url = reverse('documentation', args=(3,))

File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in reverse
  600.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in _reverse_with_prefix
  508.                              (lookup_view_s, args, kwargs, len(patterns), patterns))

Exception Type: NoReverseMatch at /documentation/
Exception Value: Reverse for 'documentation' with arguments '(3,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
File "C:\Users\Pa\Desktop\Nueva carpeta\ag\Ag\scheduler\views.py" in documentation
  82.         url = reverse('/documentation/', args=(3,))