debug.py 725 B

12345678910111213141516171819202122
  1. from functools import wraps
  2. from urllib.parse import urlparse
  3. from django.conf import settings
  4. from django.shortcuts import render
  5. from django.http import JsonResponse
  6. DEBUG = settings.DEBUG
  7. DEFAULT_ITEMS = ['username', 'token', 'enc_key', 'cipher_text']
  8. def debug_view(items=DEFAULT_ITEMS, template_name='debug.html'):
  9. def decorator(view_func):
  10. @wraps(view_func)
  11. def _wrapped_view(request, *args, **kwargs):
  12. if DEBUG and request.method == 'GET':
  13. print('render debug view')
  14. return render(request, template_name, {'items': items})
  15. else:
  16. return view_func(request, *args, **kwargs)
  17. return _wrapped_view
  18. return decorator