djangomiddleware 추가

3786 단어 입문
코드 예:
from django.utils.deprecation import MiddlewareMixin
import logging
import json

logger = logging.getLogger('router')

class resapp_middleware(MiddlewareMixin):
    
    def process_request(self, request):
        logger.info("resapp_middleware.process_request")
        logger.info(request.path)
        logger.info(request.method)
        logger.info(request.get_host())
        logger.info(request.GET)
        if request.method in ("POST","PUT","PATCH"):
            logger.info(request.body)

    def process_response(self,request,response):
        logger.info("resapp_middleware.process_response")
        logger.info('response:')
        logger.info(response)
        return response

Settings.py의 MIDDLEWARE에 사용자 정의 middleware 추가

좋은 웹페이지 즐겨찾기