You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

31 lines
1.0 KiB

import os
from django.conf import settings
from django.contrib.auth.decorators import user_passes_test
from django.shortcuts import render
from django.http import HttpResponseForbidden
@user_passes_test(lambda u: u.is_staff)
def ver_variables_entorno(request):
if not settings.DEBUG:
return HttpResponseForbidden("Acceso prohibido")
# Variables a excluir por motivos de seguridad
variables_excluidas = {'SECRET_KEY', 'DATABASES', 'EMAIL_HOST_PASSWORD', 'API_KEY'}
# Obtiene todas las variables de entorno
entorno = {key: os.getenv(key) for key in os.environ.keys() if key not in variables_excluidas}
# Obtiene todas las variables de settings excluyendo las confidenciales
configuracion = {
key: getattr(settings, key) for key in dir(settings)
if key.isupper() and key not in variables_excluidas
}
# Combina ambas en un solo diccionario
contexto = {
'entorno': entorno,
'configuracion': configuracion
}
return render(request, 'ver_entorno.html', contexto)