/Erroremail / amlqctnhel / confirmemail()中的TypeError只需要2个参数(1个给定),为什么? [英] TypeError at /confirmemail/amlqctnhel/confirmemail() takes exactly 2 arguments (1 given), why?

查看:147
本文介绍了/Erroremail / amlqctnhel / confirmemail()中的TypeError只需要2个参数(1个给定),为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:

TypeError at /confirmemail/amlqctnhel/

confirmemail() takes exactly 2 arguments (1 given)

Request Method:     GET
Request URL:    http://127.0.0.1:8000/confirmemail/amlqctnhel/
Django Version:     1.3.1
Exception Type:     TypeError
Exception Value:    

confirmemail() takes exactly 2 arguments (1 given)

Exception Location:     /usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py in get_response, line 111
Python Executable:  /usr/bin/python
Python Version:     2.6.6
Python Path:    

['/home/user1/djangoblog',
 '/usr/lib/python2.6',
 '/usr/lib/python2.6/plat-linux2',
 '/usr/lib/python2.6/lib-tk',
 '/usr/lib/python2.6/lib-old',
 '/usr/lib/python2.6/lib-dynload',
 '/usr/local/lib/python2.6/dist-packages',
 '/usr/lib/python2.6/dist-packages',
 '/usr/lib/python2.6/dist-packages/gst-0.10',
 '/usr/lib/pymodules/python2.6',
 '/usr/lib/pymodules/python2.6/gtk-2.0']

urls.py:

url(r'^confirmemail/[a-zA-Z0-9]{10}/$', 'blog.views.confirmemail'),

views.py:

def confirmemail(request,token):

user = Users.objects.get(email_token = token)
return render_to_response('confirmemail.html', {'user': user}, context_instance=RequestContext(request))

如果有人可以帮我修复它,将非常感激。谢谢。

It will be highly appreciated if someone can help me to fix it. Thank You.

推荐答案

在URLconf中,您需要使用正则表达式中的捕获组来实现视图中的位置或关键字参数。如果使用命名捕获组,则使用关键字参数;

In a URLconf, you need to use capturing groups in your regex to achieve positional or keyword arguments in your view. If you use a named capture group, then keyword arguments are used; otherwise, positional arguments are used.

这是你的 url()行应该如下所示:

Here is what your url() line should look like:

url(r'^confirmemail/([a-zA-Z0-9]{10})/$', 'blog.views.confirmemail'),
# or
url(r'^confirmemail/(?P<token>[a-zA-Z0-9]{10})/$', 'blog.views.confirmemail'),

第一种形式使用位置参数(位置参数由捕获组排序在URL中)。第二种形式使用关键字参数,在这种情况下令牌。第二种形式是更多的字符,但对参数重新排序也是安全的。

The first form uses a positional argument (and positional arguments are ordered by the capture groups in the URL). The second form uses a keyword argument, in this case token. The second form is more characters but will also be safe against parameter reordering.

这篇关于/Erroremail / amlqctnhel / confirmemail()中的TypeError只需要2个参数(1个给定),为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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