인프런 커뮤니티 질문&답변

ix219님의 프로필 이미지
ix219

작성한 질문수

파이썬 사용자를 위한 웹개발 입문 A to Z Django + Bootstrap

Post 오류창

작성

·

148

0

A server error occurred.  Please contact the administrator.

def __str__(self):
return '{} :: {}'.format(self, self.title, self.author)


이 줄들을 입력하고 cmder 열어서 python manage.py runserver 한 뒤,
창을 열고 Post 를 열어보면

흰 바탕화면에 A server error occurred. Please contact the administrator. 달랑 이 문구만 나옵니다....

그리고 cmder을 확인해보면

C:\github\django_my_website (master -> origin) (venv) λ python manage.py runserver Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). March 19, 2020 - 15:01:28 Django version 2.2, using settings 'my_site_prj.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. [19/Mar/2020 15:01:30] "GET /admin/blog/ HTTP/1.1" 200 2410 Traceback (most recent call last): File "C:\github\django_my_website\venv\lib\site-packages\django\db\models\options.py", line 565, in get_field return self.fields_map[field_name] KeyError: '__str__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\github\django_my_website\venv\lib\site-packages\django\contrib\admin\utils.py", line 262, in lookup_field f = _get_non_gfk_field(opts, name) File "C:\github\django_my_website\venv\lib\site-packages\django\contrib\admin\utils.py", line 293, in _get_non_gfk_field field = opts.get_field(name) File "C:\github\django_my_website\venv\lib\site-packages\django\db\models\options.py", line 567, in get_field raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name)) django.core.exceptions.FieldDoesNotExist: Post has no field named '__str__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\base.py", line 145, in _get_response response = self.process_exception_by_middleware(e, request) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\base.py", line 143, in _get_response response = response.render() File "C:\github\django_my_website\venv\lib\site-packages\django\template\response.py", line 106, in render self.content = self.rendered_content File "C:\github\django_my_website\venv\lib\site-packages\django\template\response.py", line 83, in rendered_content content = template.render(context, self._request) File "C:\github\django_my_website\venv\lib\site-packages\django\template\backends\django.py", line 61, in render return self.template.render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 171, in render return self._render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 163, in _render return self.nodelist.render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 937, in render bit = node.render_annotated(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 904, in render_annotated return self.render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\loader_tags.py", line 150, in render return compiled_parent._render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 163, in _render return self.nodelist.render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 937, in render bit = node.render_annotated(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 904, in render_annotated return self.render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\loader_tags.py", line 150, in render return compiled_parent._render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 163, in _render return self.nodelist.render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 937, in render bit = node.render_annotated(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 904, in render_annotated return self.render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\loader_tags.py", line 62, in render result = block.nodelist.render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 937, in render bit = node.render_annotated(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 904, in render_annotated return self.render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\loader_tags.py", line 62, in render result = block.nodelist.render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 937, in render bit = node.render_annotated(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\base.py", line 904, in render_annotated return self.render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\contrib\admin\templatetags\base.py", line 33, in render return super().render(context) File "C:\github\django_my_website\venv\lib\site-packages\django\template\library.py", line 214, in render _dict = self.func(*resolved_args, **resolved_kwargs) File "C:\github\django_my_website\venv\lib\site-packages\django\contrib\admin\templatetags\admin_list.py", line 339, in result_list 'results': list(results(cl)), File "C:\github\django_my_website\venv\lib\site-packages\django\contrib\admin\templatetags\admin_list.py", line 315, in results yield ResultList(None, items_for_result(cl, res, None)) File "C:\github\django_my_website\venv\lib\site-packages\django\contrib\admin\templatetags\admin_list.py", line 306, in __init__ super().__init__(*items) File "C:\github\django_my_website\venv\lib\site-packages\django\contrib\admin\templatetags\admin_list.py", line 229, in items_for_result f, attr, value = lookup_field(field_name, result, cl.model_admin) File "C:\github\django_my_website\venv\lib\site-packages\django\contrib\admin\utils.py", line 275, in lookup_field value = attr() File "C:\github\django_my_website\blog\models.py", line 14, in __str__ return '{} :: {}'.format(self, self.title, self.author) File "C:\github\django_my_website\blog\models.py", line 14, in __str__ return '{} :: {}'.format(self, self.title, self.author) File "C:\github\django_my_website\blog\models.py", line 14, in __str__ return '{} :: {}'.format(self, self.title, self.author) [Previous line repeated 230 more times] RecursionError: maximum recursion depth exceeded During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__ response = response or self.get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner response = response_for_exception(request, exc) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 90, in response_for_exception response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info()) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 125, in handle_uncaught_exception return debug.technical_500_response(request, *exc_info) File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response html = reporter.get_traceback_html() File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 332, in get_traceback_html t = DEBUG_ENGINE.from_string(fh.read()) UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 9735: illegal multibyte sequence During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__ response = response or self.get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner response = response_for_exception(request, exc) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 90, in response_for_exception response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info()) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 125, in handle_uncaught_exception return debug.technical_500_response(request, *exc_info) File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response html = reporter.get_traceback_html() File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 332, in get_traceback_html t = DEBUG_ENGINE.from_string(fh.read()) UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 9735: illegal multibyte sequence During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__ response = response or self.get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner response = response_for_exception(request, exc) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 90, in response_for_exception response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info()) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 125, in handle_uncaught_exception return debug.technical_500_response(request, *exc_info) File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response html = reporter.get_traceback_html() File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 332, in get_traceback_html t = DEBUG_ENGINE.from_string(fh.read()) UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 9735: illegal multibyte sequence During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__ response = response or self.get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner response = response_for_exception(request, exc) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 90, in response_for_exception response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info()) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 125, in handle_uncaught_exception return debug.technical_500_response(request, *exc_info) File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response html = reporter.get_traceback_html() File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 332, in get_traceback_html t = DEBUG_ENGINE.from_string(fh.read()) UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 9735: illegal multibyte sequence During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__ response = response or self.get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner response = response_for_exception(request, exc) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 90, in response_for_exception response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info()) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 125, in handle_uncaught_exception return debug.technical_500_response(request, *exc_info) File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response html = reporter.get_traceback_html() File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 332, in get_traceback_html t = DEBUG_ENGINE.from_string(fh.read()) UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 9735: illegal multibyte sequence During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__ response = response or self.get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner response = response_for_exception(request, exc) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 90, in response_for_exception response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info()) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 125, in handle_uncaught_exception return debug.technical_500_response(request, *exc_info) File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response html = reporter.get_traceback_html() File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 332, in get_traceback_html t = DEBUG_ENGINE.from_string(fh.read()) UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 9735: illegal multibyte sequence During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__ response = response or self.get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner response = response_for_exception(request, exc) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 90, in response_for_exception response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info()) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 125, in handle_uncaught_exception return debug.technical_500_response(request, *exc_info) File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response html = reporter.get_traceback_html() File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 332, in get_traceback_html t = DEBUG_ENGINE.from_string(fh.read()) UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 9735: illegal multibyte sequence During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\Lee Ji Hyun\anaconda3\lib\wsgiref\handlers.py", line 137, in run self.result = application(self.environ, self.start_response) File "C:\github\django_my_website\venv\lib\site-packages\django\contrib\staticfiles\handlers.py", line 65, in __call__ return self.application(environ, start_response) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\wsgi.py", line 141, in __call__ response = self.get_response(request) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\base.py", line 75, in get_response response = self._middleware_chain(request) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner response = response_for_exception(request, exc) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 90, in response_for_exception response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info()) File "C:\github\django_my_website\venv\lib\site-packages\django\core\handlers\exception.py", line 125, in handle_uncaught_exception return debug.technical_500_response(request, *exc_info) File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response html = reporter.get_traceback_html() File "C:\github\django_my_website\venv\lib\site-packages\django\views\debug.py", line 332, in get_traceback_html t = DEBUG_ENGINE.from_string(fh.read()) UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 9735: illegal multibyte sequence [19/Mar/2020 15:01:33] "GET /admin/blog/post/ HTTP/1.1" 500 59




너무 길어서 멘붕이 되는데 무슨 소린지 모르겠어서 끝 줄 오류부분
UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 9735: illegal multibyte sequence 이것만 검색해서 찾아봤더니
debug.py 에서 비어있던 open method에서 encoding = "utf-8" 도 기입했고 span 은 고칠게 따로 없었고 그랬습니다..

뭐가 잘못된 것일까요,,,

답변 2

0

ix219님의 프로필 이미지
ix219
질문자

__str__의 return을 제가 잘못 적었네요ㅠㅠ이것만 고쳤는데 잘나옵니다,,,,, 빠른 답변 너무 감사해요!! 

0

SungYong Lee님의 프로필 이미지
SungYong Lee
지식공유자

여러가지 문제가 복합된 것 같습니다. 

일단, indentation (4칸 들여쓰기)이 잘 되어 있는지 확인해주세요. Post 클래스 안에 __str__ 함수가 있어야 합니다.

__str__ 의 return 도 잘못되어 있습니다. 

def __str__(self):
return '{} :: {}'.format(self, self.title, self.author)

이 아니라, 

def __str__(self):
return '{} :: {}'.format(self.title, self.author)

입니다. 

시도해보시고 안되면 또 말씀해주세요!

ix219님의 프로필 이미지
ix219

작성한 질문수

질문하기