Я не уверен, что сопровождающий проекта для django -simple-captcha должен исправить свой код, чтобы он был HTML5 действительным, или есть способ исправить ошибки проверки HTML5, используя метод рендеринга ниже. Буду признателен за любую помощь.
https://django-simple-captcha.readthedocs.io/en/latest/advanced.html#rendering
https://github.com/mbi/django-simple-captcha/blob/master/captcha/templates/captcha/hidden_field.html
https://github.com/mbi/django-simple-captcha/blob/master/captcha/templates/captcha/field.html
https://github.com/mbi/django-simple-captcha/blob/master/captcha/templates/captcha/text_field.html
Attribute autocorrect not allowed on element input at this point.
<input type="text" name="captcha_1" class="form-control mt-2" placeholder="Solve the captcha" required id="id_captcha_1" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false"></p>
Attribute required not allowed on element input at this point.
<input type="hidden" name="captcha_0" value="e83b1ca0e5149574b9b19098074dd3de390b339f" class="form-control mt-2" placeholder="Solve the captcha" required id="id_captcha_0">
Attribute placeholder is only allowed when the input type is email, number, password, search, tel, text, or url.
<input type="hidden" name="captcha_0" value="e83b1ca0e5149574b9b19098074dd3de390b339f" class="form-control mt-2" placeholder="Solve the captcha" required id="id_captcha_0">
--------------
Forms.py:
class CustomCaptchaTextInput(CaptchaTextInput):
template_name = 'custom_field.html'
class ContactForm(forms.Form):
captcha = CaptchaField(widget=CustomCaptchaTextInput)
def __init__(self, *args, **kwargs):
super(ContactForm, self).__init__(*args, **kwargs)
self.fields['captcha'].widget.attrs['class'] = 'form-control mt-2'
self.fields['captcha'].widget.attrs['placeholder'] = 'Solve the captcha'
self.fields['captcha'].label = "Enter the correct captcha as shown in the image"
--------------
custom_field.html:
{% load i18n %}
{% spaceless %}
<label class="control-label">{{ label }}</label>
<img src="{{ image }}" alt="captcha" class="captcha" />
<br/>
<audio class="w-100 mt-2" controls>
<source src="{{ audio }}" />
</audio>
{% include "django/forms/widgets/multiwidget.html" %}
{% endspaceless %}
---------------
Settings.py:
INSTALLED_APPS = [
'django.forms',
'captcha',
]
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
---------------