mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 05:11:09 -05:00
Disable Cloudflare Turnstile on login/signup pages when DEBUG is True
This commit is contained in:
@@ -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)
|
||||
|
||||
1
templates/accounts/turnstile_widget_empty.html
Normal file
1
templates/accounts/turnstile_widget_empty.html
Normal file
@@ -0,0 +1 @@
|
||||
<!-- Empty template when DEBUG is True -->
|
||||
Reference in New Issue
Block a user