“得到一个意想不到的关键字参数”ticket_id“” [英] "got an unexpected keyword argument 'ticket_id'"

查看:340
本文介绍了“得到一个意想不到的关键字参数”ticket_id“”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目管理应用程序。一个项目可以拥有与项目相关的票据,并在项目下面的模板中以及项目的票据。



但是,我收到错误下面的代码,我无法弄清楚它的意思和解决方法:

 异常值:show_ticket()得到一个意想不到的关键字参数'ticket_id'
异常位置:/Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/django/contrib/auth/decorators.py在_wrapped_view中,第20行

可能有什么问题?



项目模板

  {%为门票%} 
< span> ; {{ticket}}< / span>
< a href ={%url show_ticket project.id ticket.id%}>显示票证< / a>< br />
{%endfor%}

urls.py: / p>

  url(r'^ project /(?P< project_id> \d +)/ ticket /(?P< ticket_id& \\ d +)/ $','project_app.views.show_ticket',name =show_ticket),

视图:

  @login_required 
def show_ticket(request,project_id):
ticket = get_object_or_404(Ticket,pk = ticket_id)

return render(request,'projects / show_ticket.html',{ticket:ticket})


解决方案

您的 show_ticket view只接受一个变量 - 项目编号。您在该视图中使用两个变量( project.id ticket.id



您的视图网址已设置为接受 ticket_id ,因此您只需要更改视图即可接受 ticket_id 还有:

  def show_ticket(request,project_id,ticket_id):
....


I'm working on a project management app. A project can have tickets, which are tied to the project and in the template below a project is rendered, as well as the project's tickets.

However, I get an error with the code below and I can't figure out what it means and how to solve it:

Exception Value:    show_ticket() got an unexpected keyword argument 'ticket_id'
Exception Location: /Library/Python/2.7/site-packages/Django-1.4.5-py2.7.egg/django/contrib/auth/decorators.py in _wrapped_view, line 20

What can be wrong?

project template:

{% for ticket in tickets %}
    <span>{{ ticket }}</span>
    <a href="{% url show_ticket project.id ticket.id %}">Show ticket</a><br/>
{% endfor %}

urls.py:

url(r'^project/(?P<project_id>\d+)/ticket/(?P<ticket_id>\d+)/$', 'project_app.views.show_ticket', name="show_ticket"),

view:

@login_required
def show_ticket(request, project_id):
    ticket = get_object_or_404(Ticket, pk = ticket_id)

    return render(request, 'projects/show_ticket.html', {"ticket" : ticket})

解决方案

Your show_ticket view only accepts one variable - the project id. You are calling the reverse on that view with two variables - project.id and ticket.id.

Your URL for the view is already setup to accept the ticket_id, so you just need to change your view to accept the ticket_id as well:

def show_ticket(request, project_id, ticket_id):
    ....

这篇关于“得到一个意想不到的关键字参数”ticket_id“”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆