Disable Cloudflare Turnstile on login/signup pages when DEBUG is True

This commit is contained in:
pacnpal
2024-11-13 15:56:42 +00:00
parent 537ea0fc07
commit ec626b4124
2 changed files with 15 additions and 4 deletions

View File

@@ -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)