Django django 정보template.base.VariableDoesNotExist

30266 단어 Djangopython
운영 환경
pycharm 2017.1 Django 2.0.1 python 3.6.1
Django 웹 페이지에 logger 추가
settings에서.py에 logging 대응 코드를 추가하려면:
LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
            'format': '%(asctime)s [%(threadName)s:%(thread)d] [%(name)s:%(lineno)d] [%(module)s:%(funcName)s] [%(levelname)s]- %(message)s'}  #    
    },
    'filters': {
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
            'include_html': True,
            },
        'default': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': 'log/all.log',     #      
            'maxBytes': 1024*1024*5,                  #    
            'backupCount': 5,                         #    
            'formatter':'standard',                   #    formatters    
        },
        'error': {
            'level':'ERROR',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': 'log/error.log',
            'maxBytes':1024*1024*5,
            'backupCount': 5,
            'formatter':'standard',
            },
        'console':{
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'standard'
        },
        'request_handler': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': 'log/script.log',
            'maxBytes': 1024*1024*5,
            'backupCount': 5,
            'formatter':'standard',
            },
        'scprits_handler': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename':'log/script.log',
            'maxBytes': 1024*1024*5,
            'backupCount': 5,
            'formatter':'standard',
            }
    },
    'loggers': {
        'django': {
            'handlers': ['default', 'console'],
            'level': 'DEBUG',
            'propagate': False
        },
        'django.request': {
            'handlers': ['request_handler'],
            'level': 'DEBUG',
            'propagate': False,
            },
        'scripts': {
            'handlers': ['scprits_handler'],
            'level': 'INFO',
            'propagate': False
        },
        'blog.views': {
            'handlers': ['default', 'error'],
            'level': 'DEBUG',
            'propagate': True
        },
    }
}

views에서.py의 참조 코드:
import logging
logger=logging.getLogger('blog.views')#blog   app  

웹 페이지를 실행하는 동안 다음과 같은 오류가 발생했습니다(부분).
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/template/base.py", line 835, in _resolve_lookup
    current = current[bit]
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/template/context.py", line 83, in __getitem__
    raise KeyError(key)
KeyError: 'is_popup'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/template/base.py", line 841, in _resolve_lookup
    if isinstance(current, BaseContext) and getattr(type(current), bit):
AttributeError: type object 'RequestContext' has no attribute 'is_popup'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/template/base.py", line 849, in _resolve_lookup
    current = current[int(bit)]
ValueError: invalid literal for int() with base 10: 'is_popup'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/template/base.py", line 856, in _resolve_lookup
    (bit, current))  # missing attribute
django.template.base.VariableDoesNotExist: Failed lookup for key [is_popup] in [{'True': True, 'False': False, 'None': None}, {'csrf_token': ._get_val at 0x400fa04>>, 'request': '/admin/'>, 'user': >, 'perms': 0x44ade8c>, 'messages': 0x4508aac>, 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10, 'INFO': 20, 'SUCCESS': 25, 'WARNING': 30, 'ERROR': 40}, 'click_count_list': 'title': '2'}, {'title': '1'}, {'title': '7'}, {'title': '6'}, {'title': '3'}, {'title': '5'}]>, 'article_comment_list': [1>, 7>, 6>, 5>, 4>, 3>], 'comment_count_list': 'article': 6, 'comment_count': 2}, {'article': 7, 'comment_count': 2}, {'article': 1, 'comment_count': 1}, {'article': 2, 'comment_count': 1}, {'article': 3, 'comment_count': 1}, {'article': 4, 'comment_count': 1}]>, 'tag_list': 1>, 2>, 3>, 4>, 5>, 6>, 7>, 8>]>, 'links': , , ]>, 'category_list': , , , , , , ]>, 'archive_list': ['2018/02    '], 'signature': '    ,       ;    ,       ;    ,      ;    ,       。', 'intro': 'panos    '}, {}, {'site_title': 'Django site admin', 'site_header': 'Django administration', 'site_url': '/', 'has_permission': True, 'available_apps': [{'name': 'Authentication and Authorization', 'app_label': 'auth', 'app_url': '/admin/auth/', 'has_module_perms': True, 'models': [{'name': 'Groups', 'object_name': 'Group', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/auth/group/', 'add_url': '/admin/auth/group/add/'}]}, {'name': 'Blog_App', 'app_label': 'blog_app', 'app_url': '/admin/blog_app/', 'has_module_perms': True, 'models': [{'name': '  ', 'object_name': 'Category', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/category/', 'add_url': '/admin/blog_app/category/add/'}, {'name': '    ', 'object_name': 'Links', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/links/', 'add_url': '/admin/blog_app/links/add/'}, {'name': '  ', 'object_name': 'Ad', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/ad/', 'add_url': '/admin/blog_app/ad/add/'}, {'name': '  ', 'object_name': 'Article', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/article/', 'add_url': '/admin/blog_app/article/add/'}, {'name': '  ', 'object_name': 'Tag', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/tag/', 'add_url': '/admin/blog_app/tag/add/'}, {'name': '  ', 'object_name': 'User', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/user/', 'add_url': '/admin/blog_app/user/add/'}, {'name': '  ', 'object_name': 'Comment', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/comment/', 'add_url': '/admin/blog_app/comment/add/'}]}], 'title': 'Site administration', 'app_list': [{'name': 'Authentication and Authorization', 'app_label': 'auth', 'app_url': '/admin/auth/', 'has_module_perms': True, 'models': [{'name': 'Groups', 'object_name': 'Group', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/auth/group/', 'add_url': '/admin/auth/group/add/'}]}, {'name': 'Blog_App', 'app_label': 'blog_app', 'app_url': '/admin/blog_app/', 'has_module_perms': True, 'models': [{'name': '  ', 'object_name': 'Category', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/category/', 'add_url': '/admin/blog_app/category/add/'}, {'name': '    ', 'object_name': 'Links', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/links/', 'add_url': '/admin/blog_app/links/add/'}, {'name': '  ', 'object_name': 'Ad', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/ad/', 'add_url': '/admin/blog_app/ad/add/'}, {'name': '  ', 'object_name': 'Article', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/article/', 'add_url': '/admin/blog_app/article/add/'}, {'name': '  ', 'object_name': 'Tag', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/tag/', 'add_url': '/admin/blog_app/tag/add/'}, {'name': '  ', 'object_name': 'User', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/user/', 'add_url': '/admin/blog_app/user/add/'}, {'name': '  ', 'object_name': 'Comment', 'perms': {'add': True, 'change': True, 'delete': True}, 'admin_url': '/admin/blog_app/comment/', 'add_url': '/admin/blog_app/comment/add/'}]}], 'LANGUAGE_CODE': 'en-us', 'LANGUAGE_BIDI': False}]

검토한 결과 이 exception은 Django의 취약점입니다.
  • 도장고 홈페이지
  • Github

  • 유감스럽게도 지금은 효과적인 해결책을 찾지 못하고 있습니다.

    좋은 웹페이지 즐겨찾기