请求表单时如何发送参数

时间:2010-07-07 01:14:27

标签: django django-forms validation

在用户注册期间,我正在调用一些自定义函数:

def user_created(sender, user, request, **kwargs):
    form = ExtendedRegistrationForm(validateemail=True, request.POST, request.FILES)

申请表格时,我需要提供额外的bool参数validateemail。这虽然给我错误:

Exception Type: SyntaxError at / Exception Value: ('non-keyword arg after keyword arg', ('/home/myapp/regbackend.py', 59, None, 'form = ExtendedRegistrationForm(dontvalidateemail=True, request.POST, request.FILES)\n'))

我做错了什么?此外,如果我想在我的表单中使用此参数,是否需要添加自定义init方法?喜欢:

def __init__(self, *args, **kwargs):
    try:
        validate = args['validate']
    except:
        pass           
    if not validate:
        validate = False           
    super(ExtendedRegistrationForm, self).__init__(*args, **kwargs)

1 个答案:

答案 0 :(得分:1)

关键字参数必须在位置参数之后。尝试:

form = ExtendedRegistrationForm(request.POST, request.FILES, validateemail=True)