Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
9mido opened this issue Jun 7, 2020 · 1 comment

Comments

@9mido
Copy link

9mido commented Jun 7, 2020

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 9mido changed the title Unable to override {{hidden_field}} and {{text_field}} in my project templates & virtual environment folders Unable to override {{hidden_field}} and {{text_field}} in my project templates, virtual environment folders, & custom_field.html Jun 7, 2020
@bastiaan85
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants