diff --git a/accounts/templatetags/turnstile_tags.py b/accounts/templatetags/turnstile_tags.py index 6cddcd67..aa1e16eb 100644 --- a/accounts/templatetags/turnstile_tags.py +++ b/accounts/templatetags/turnstile_tags.py @@ -1,14 +1,24 @@ from django import template from django.conf import settings +from django.template.loader import render_to_string register = template.Library() -@register.inclusion_tag('accounts/turnstile_widget.html') +@register.simple_tag def turnstile_widget(): """ Template tag to render the Cloudflare Turnstile widget. + When DEBUG is True, renders an empty template. + When DEBUG is False, renders the normal widget. Usage: {% load turnstile_tags %}{% turnstile_widget %} """ - return { - 'site_key': settings.TURNSTILE_SITE_KEY - } + if settings.DEBUG: + template_name = 'accounts/turnstile_widget_empty.html' + context = {} + else: + template_name = 'accounts/turnstile_widget.html' + context = { + 'site_key': settings.TURNSTILE_SITE_KEY + } + + return render_to_string(template_name, context) diff --git a/templates/accounts/turnstile_widget_empty.html b/templates/accounts/turnstile_widget_empty.html new file mode 100644 index 00000000..d81e80a3 --- /dev/null +++ b/templates/accounts/turnstile_widget_empty.html @@ -0,0 +1 @@ +