0
몇 가지 실패한 양식 전송 시도 후에 추가 captcha 필드를 표시하려고합니다.Django의 일반적인보기에있는 동적 양식 필드
일반 양식을 처리하는 동안 pretty easy이지만 일반적인보기에서 어떻게 얻을 수 있습니까?
# models.py
class MyCreateView(CreateView):
form_class = MyForm
model = MyModel
def form_valid(self, form):
if show_captcha:
form = MyForm(form, captcha=True)
return self.form_invalid(form)
# forms.py
class MyForm(ModelForm):
def __init__(self, *args, **kwargs):
captcha = kwargs.pop('captcha', None)
super(MyForm, self).__init__(*args, **kwargs)
if captcha:
self.fields['captcha'] = ReCaptchaField()
class Meta:
model = MyModel
fields = ['myfield']
편집 :
나는 내 코드를 업데이트했습니다. 내가 오류는 다음과 같습니다
'MyForm' object has no attribute 'get'
그것은 라인에, 내 템플릿을 가리키는 : 당신이 일반적인보기를 사용하는 경우
{{ form.as_p }}