django_example_ynh/django_ynh/views.py

28 lines
802 B
Python
Raw Normal View History

2020-12-28 12:35:36 +01:00
import logging
2020-12-23 19:53:13 +01:00
import pprint
from django.conf import settings
2020-12-28 12:35:36 +01:00
from django.contrib.auth import get_user_model
from django.http.response import HttpResponse
2020-12-23 19:53:13 +01:00
from django.shortcuts import redirect
2020-12-28 12:35:36 +01:00
logger = logging.getLogger(__name__)
2020-12-23 19:53:13 +01:00
def request_media_debug_view(request):
""" debug request.META """
2020-12-28 12:35:36 +01:00
assert settings.DEBUG is True, 'Only in DEBUG mode available!'
2020-12-23 19:53:13 +01:00
if not request.user.is_authenticated:
2020-12-28 12:35:36 +01:00
logger.info('Deny debug view: User not logged in!')
UserModel = get_user_model()
logger.info('Existing users are: %s', ', '.join(f'"{user}"' for user in UserModel.objects.all()))
2020-12-23 19:53:13 +01:00
return redirect('admin:index')
meta = pprint.pformat(request.META)
html = f'<html><body>request.META: <pre>{meta}</pre></body></html>'
return HttpResponse(html)