Django 无法解析';创建订单';没有找到任何参数
这个问题已经在这里讨论过了 但对于如何解决这个问题,却没有提及。有人能帮忙吗 这是代码,我收到一个错误 dashboard.htmlDjango 无法解析';创建订单';没有找到任何参数,django,Django,这个问题已经在这里讨论过了 但对于如何解决这个问题,却没有提及。有人能帮忙吗 这是代码,我收到一个错误 dashboard.html <div class="col-md-7"> <h5>LAST 5 ORDERS</h5> <hr> <div class="card card-body"> <a class="btn btn-prima
<div class="col-md-7">
<h5>LAST 5 ORDERS</h5>
<hr>
<div class="card card-body">
<a class="btn btn-primary btn-sm btn-block" href="{% url 'create_order' customer.id %}">Create Order</a>
<table class="table table-sm">
<tr>
<th>Product</th>
<th>Date Orderd</th>
<th>Status</th>
<th>Update</th>
<th>Remove</th>
</tr>
{% for order in orders %}
<tr>
<td>{{order.product}}</td>
<td>{{order.date_created}}</td>
<td>{{order.status}}</td>
<td><a class="btn btn-sm btn-info" href="{% url 'update_order' order.id %}">Update</a></td>
<td><a class="btn btn-sm btn-danger" href="{% url 'delete_order' order.id %}">Delete</a></td>
</tr>
{% endfor %}
</table>
</div>
有人告诉我,创建订单按钮有注释,但没有注释
这是我遇到的例外情况的一部分
跟踪误差
Internal Server Error: /
Traceback (most recent call last):
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "C:\Users\s5114509\PycharmProjects\Demo\crm\accounts\decorators.py", line 38, in wrapper_function
return view_func(request,*args,**kwargs)
File "C:\Users\s5114509\PycharmProjects\Demo\crm\accounts\views.py", line 70, in home
return render(request, 'accounts/dashboard.html', context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\shortcuts.py", line 19, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\loader.py", line 62, in render_to_string
return template.render(context, request)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 171, in render
return self._render(context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\defaulttags.py", line 443, in render
url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\urls\base.py", line 87, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site-packages\django\urls\resolvers.py", line 677, in _reverse_with_prefix
raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'create_order' with arguments '('',)' not found. 1 pattern(s) tried: ['create_order/(?P<pk>[^/]+)/$']
[14/Sep/2020 14:50:07] "GET / HTTP/1.1" 500 181933
内部服务器错误:/
回溯(最近一次呼叫最后一次):
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\core\handlers\exception.py”,第34行,在内部
响应=获取响应(请求)
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\core\handlers\base.py”,第115行,在get\U响应中
response=self.process\u异常\u由\u中间件(e,请求)
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\core\handlers\base.py”,第113行,在get\U响应中
响应=包装的回调(请求,*回调参数,**回调参数)
文件“C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site packages\django\contrib\auth\decorators.py”,第21行,在包装视图中
返回视图功能(请求,*args,**kwargs)
文件“C:\Users\s5114509\PycharmProjects\Demo\crm\accounts\decorators.py”,第38行,在包装函数中
返回视图功能(请求,*args,**kwargs)
文件“C:\Users\s5114509\PycharmProjects\Demo\crm\accounts\views.py”,第70行,在home中
返回呈现(请求“accounts/dashboard.html”上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\shortcuts.py”,第19行,在render中
content=loader.render_to_string(模板名称、上下文、请求、using=using)
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\template\loader.py”,第62行,呈现为字符串
返回template.render(上下文、请求)
文件“C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site packages\django\template\backends\django.py”,第61行,在render中
返回self.template.render(上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\template\base.py”,第171行,在render中
返回self.\u呈现(上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\template\base.py”,第163行,在\u render中
返回self.nodelist.render(上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\template\base.py”,第936行,在render中
位=节点。带注释的渲染(上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site packages\django\template\base.py”,第903行,在render\u注释中
返回self.render(上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site packages\django\template\loader\u tags.py”,第150行,在render中
返回编译的\u父对象。\u呈现(上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\template\base.py”,第163行,在\u render中
返回self.nodelist.render(上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\template\base.py”,第936行,在render中
位=节点。带注释的渲染(上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site packages\django\template\base.py”,第903行,在render\u注释中
返回self.render(上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site packages\django\template\loader\u tags.py”,第62行,在render中
结果=block.nodelist.render(上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\template\base.py”,第936行,在render中
位=节点。带注释的渲染(上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site packages\django\template\base.py”,第903行,在render\u注释中
返回self.render(上下文)
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\template\defaulttags.py”,第443行,在render中
url=reverse(视图名称,args=args,kwargs=kwargs,当前应用程序=当前应用程序)
文件“C:\Users\s5114509\AppData\Local\Programs\Python38\lib\site packages\django\url\base.py”,第87行,相反
将iri_返回到_uri(解析器。_使用_前缀反向_(视图,前缀,*args,**kwargs))
文件“C:\Users\s5114509\AppData\Local\Programs\Python\Python38\lib\site packages\django\url\resolvers.py”,第677行,带前缀的\u reverse\u
提升NoReverseMatch(msg)
django.url.exceptions.NoReverseMatch:找不到参数为“(“”,)”的“创建顺序”的反向。尝试了1个模式:[“创建订单/(?P[^/]+)/$”]
[14/Sep/2020 14:50:07]“GET/HTTP/1.1”500 181933
我得到了上述问题的答案。实际问题是
<a class="btn btn-primary btn-sm btn-block" href="{% url 'create_order' customer.id %}">Create Order</a>
这里customer.id的值为空,它需要参数。创建订单1
因此,当我调试问题时,我能够解决。。所以我用..代替了同样的陈述。。(需要为所有客户添加更多逻辑)
查询第一个客户
多谢各位
<a class="btn btn-primary btn-sm btn-block" href="{% url 'create_order' customer.id %}">Create Order</a>
<a class="btn btn-primary btn-sm btn-block" href= "{% url 'create_order' customers.first.id %}">Create Order</a>