我使用以下功能运行删除操作
删除成功但发生错误
def todo_delete (request, pk):
# template = 'todo / todo_confirm_delete.html'
todo = get_object_or_404 (Todo, pk = pk)
todo.delete ()
Profile.objects.filter (Q (user = request.user.id)). Update (uncompletecount = F ('uncompletecount') - 1)
print ("todo", todo, delete ')
return reverse_lazy ('todo: todo_list')
错误
AttributeError: '__proxy__' object has no attribute 'get'
这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误这是错误错误这是错误这是错误这是错误这是错误这是错误s是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误,这是错误
错误
(venv) (base) C:\django_inflearn2>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
May 30, 2019 - 14:28:12
Django version 2.2, using settings 'reservation_app.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[30/May/2019 14:28:12] "GET /todo/ HTTP/1.1" 200 15022
[30/May/2019 14:28:12] "GET /summernote/editor/id_text/ HTTP/1.1" 200 6349
[30/May/2019 14:28:12] "GET /static/summernote/lang/summernote-en-US.min.js?_=1559194092912 HTTP/1.1" 200 27
Traceback (most recent call last):
File "C:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\utils\deprecation.py", line 96, in __call__
response = self.process_response(request, response)
File "C:\django_inflearn2\venv\lib\site-packages\django\middleware\clickjacking.py", line 26, in process_response
if response.get('X-Frame-Options') is not None:
AttributeError: '__proxy__' object has no attribute 'get'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "C:\django_inflearn2\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:\django_inflearn2\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:\django_inflearn2\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response
html = reporter.get_traceback_html()
File "C:\django_inflearn2\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:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "C:\django_inflearn2\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:\django_inflearn2\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:\django_inflearn2\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response
html = reporter.get_traceback_html()
File "C:\django_inflearn2\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:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "C:\django_inflearn2\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:\django_inflearn2\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:\django_inflearn2\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response
html = reporter.get_traceback_html()
File "C:\django_inflearn2\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:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "C:\django_inflearn2\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:\django_inflearn2\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:\django_inflearn2\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response
html = reporter.get_traceback_html()
File "C:\django_inflearn2\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:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "C:\django_inflearn2\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:\django_inflearn2\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:\django_inflearn2\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response
html = reporter.get_traceback_html()
File "C:\django_inflearn2\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:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "C:\django_inflearn2\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:\django_inflearn2\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:\django_inflearn2\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response
html = reporter.get_traceback_html()
File "C:\django_inflearn2\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\hyunsepk\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\django_inflearn2\venv\lib\site-packages\django\contrib\staticfiles\handlers.py", line 65, in __call__
return self.application(environ, start_response)
File "C:\django_inflearn2\venv\lib\site-packages\django\core\handlers\wsgi.py", line 141, in __call__
response = self.get_response(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\core\handlers\base.py", line 75, in get_response
response = self._middleware_chain(request)
File "C:\django_inflearn2\venv\lib\site-packages\django\core\handlers\exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "C:\django_inflearn2\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:\django_inflearn2\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:\django_inflearn2\venv\lib\site-packages\django\views\debug.py", line 94, in technical_500_response
html = reporter.get_traceback_html()
File "C:\django_inflearn2\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
[30/May/2019 14:28:17] "GET /todo/60/delete/ HTTP/1.1" 500 59
感谢让我知道错误的原因以及解决方法
答案 0 :(得分:2)
您的视图todo_delete
需要html响应,而您返回的是url
。
我相信
的目的return reverse_lazy ('todo: todo_list')
是用于重定向到某个todo_list
页面。
尝试使用redirect:
return redirect(reverse_lazy ('todo: todo_list'))
您明白了。我尚未测试代码,但我相信您会理解的。