django-simple-captcha icon indicating copy to clipboard operation
django-simple-captcha copied to clipboard

Unable to override {{hidden_field}} and {{text_field}} in my project templates, virtual environment folders, & custom_field.html

Open 9mido opened this issue 4 years ago • 1 comments

It is very tough to edit these fields in forms.py and custom_field.html rendering since forms.py CaptchaField(widget=CustomCaptchaTextInput) will generate input HTML tags for both id_captcha_0 and id_captcha_0 with the same exact attributes you include for self.fields['captcha'].widget.attrs['...'] and I cannot figure out how to edit them in forms.py separately.

This relates to the same code as in the HTML5 validation errors issue if you want to look at it there.

It would be nice to use https://pypi.org/project/django-widget-tweaks/ to customize them but even that does not work when placing these tags inside of custom_field.html.

Also placing {{id}}, {{name}}, {{key}} inside of custom_field.html does not work.

Need a way to separately edit {{hidden_field}} and {{text_field}} in forms.py or override the templates using the old style rendering but that does not work anymore. Why not include old style rendering and current custom_field.html rendering at the same time?

Tried overriding templates by putting the following files inside of my project_name/templates/captcha/ with no effect after changing the contents of the files: ​ 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 ​

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,"templates")],
        'APP_DIRS': True,
    }
]

​ Editing templates inside of this location also did not have an effect: /home/user/.local/share/virtualenvs/project_name/lib/python3.7/site-packages/captcha/templates/captcha/

Not sure if it has to do with the folder being named 'captcha' which is exactly the same as django-recaptcha if using both of those apps at the same time. But I uninstalled django-recaptcha and did not see any improvement.

9mido avatar Jun 07 '20 22:06 9mido

Managed to get it working using different names for the template files, eg

CAPTCHA_IMAGE_TEMPLATE = "captcha/new_image.html"
CAPTCHA_TEXT_FIELD_TEMPLATE = "captcha/new_text_field.html"
CAPTCHA_FIELD_TEMPLATE = "captcha/new_field.html"

bastiaan85 avatar Apr 01 '22 14:04 bastiaan85