mbi / django-simple-captcha

Django Simple Captcha is an extremely simple, yet highly customizable Django application to add captcha images to any Django form.
http://django-simple-captcha.readthedocs.io/en/latest/
MIT License
1.38k stars 319 forks source link

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

Open 9mido opened 4 years ago

9mido commented 4 years ago

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.htmlhttps://github.com/mbi/django-simple-captcha/blob/master/captcha/templates/captcha/field.htmlhttps://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.

bastiaan85 commented 2 years ago

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"