12345678910111213141516171819202122 |
- from functools import wraps
- from urllib.parse import urlparse
- from django.conf import settings
- from django.shortcuts import render
- from django.http import JsonResponse
- DEBUG = settings.DEBUG
- DEFAULT_ITEMS = ['username', 'token', 'enc_key', 'cipher_text']
- def debug_view(items=DEFAULT_ITEMS, template_name='debug.html'):
- def decorator(view_func):
- @wraps(view_func)
- def _wrapped_view(request, *args, **kwargs):
- if DEBUG and request.method == 'GET':
- print('render debug view')
- return render(request, template_name, {'items': items})
- else:
- return view_func(request, *args, **kwargs)
- return _wrapped_view
- return decorator
|