오지's blog

django.utils.datastructures.MultiValueDictKeyError: 발생 본문

개발노트/Python

django.utils.datastructures.MultiValueDictKeyError: 발생

오지구영ojjy90 2020. 11. 24. 11:22
728x90
반응형

Traceback (most recent call last): File "C:\workspaces\foreign\venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner response = get_response(request) File "C:\workspaces\foreign\venv\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\workspaces\foreign\config\sender\views.py", line 16, in new_request req.sender_name = request.POST['sender_name'] File "C:\workspaces\foreign\venv\lib\site-packages\django\utils\datastructures.py", line 78, in __getitem__ raise MultiValueDictKeyError(key) django.utils.datastructures.MultiValueDictKeyError: 'sender_name'

 

 

 

원인: 모델의 항목과 html의 항목이 일치 하지 않았음

 

model.py

class Sender(models.Model):
sender_name = models.CharField(max_length=256)
created_at = models.DateTimeField(auto_now_add=True)

 

new.html

<form action="" method="POST" >
{% csrf_token %}
<input type="text" name="sender_item">
<input type="submit" value="접수하기">
</form>

Comments