Skip to content

Overriding Templates #334

Answered by mfisco
9mido asked this question in Q&A
Discussion options

You must be logged in to vote

For others who stumble on this and are unable to set the FORM_RENDERER, I did the following which ended up working for me:

  1. Subclass the ReCaptchaV3 and override the render method:
# myproject/widgets.py

from captcha.widgets import ReCaptchaV3

from django.template import loader
from django.utils.safestring import mark_safe

class CustomReCaptchaV3(ReCaptchaV3):
    template_name = "recaptcha/widget_v3.html"

    def render(self, name, value, attrs=None, renderer=None):
        context = self.get_context(name, value, attrs)
        template = loader.get_template(self.template_name)
        return mark_safe(template.render(context))
  1. Add it to your form:
# myproject/forms.py
from captcha.

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by thibaudcolas
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants
Converted from issue

This discussion was converted from issue #211 on November 24, 2023 07:10.