Django django 정보template.base.VariableDoesNotExist
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의 취약점입니다.
유감스럽게도 지금은 효과적인 해결책을 찾지 못하고 있습니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Django 라우팅 계층 URLconf 작용 및 원리 해석URL 구성(URLconf)은 Django가 지원하는 웹 사이트의 디렉토리와 같습니다.그것의 본질은 URL과 이 URL을 호출할 보기 함수 사이의 맵표입니다. 위의 예제에서는 URL의 값을 캡처하고 위치 매개 변수로...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.