【发布时间】:2021-06-28 00:22:31
【问题描述】:
我试图将图像插入到 sqlite,但它没有用它总是给我错误 这是我的代码
def index(request):
dbname = 'user1'
cursor = connections[dbname].cursor()
if request.POST.get('done'):
cursor.execute('insert into images values(%s)', [request.FILES['myfile']])
return render(request, 'index.html')
这是错误
MultiValueDictKeyError at /index
'myfile'
Request Method: POST
Request URL: http://127.0.0.1:8000/index
Django Version: 3.2
Exception Type: MultiValueDictKeyError
Exception Value:
'myfile'
Exception Location: D:\omar\pythonProject\venv\lib\site-packages\django\utils\datastructures.py, line 78, in __getitem__
Python Executable: D:\omar\pythonProject\venv\Scripts\python.exe
Python Version: 3.9.2
Python Path:
['D:\\omar\\pythonProject',
'C:\\Users\\taha_lab\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip',
'C:\\Users\\taha_lab\\AppData\\Local\\Programs\\Python\\Python39\\DLLs',
'C:\\Users\\taha_lab\\AppData\\Local\\Programs\\Python\\Python39\\lib',
'C:\\Users\\taha_lab\\AppData\\Local\\Programs\\Python\\Python39',
'D:\\omar\\pythonProject\\venv',
'D:\\omar\\pythonProject\\venv\\lib\\site-packages']
Server time: Mon, 28 Jun 2021 00:18:52 +0000
Traceback Switch to copy-and-paste view
D:\omar\pythonProject\venv\lib\site-packages\django\utils\datastructures.py, line 76, in __getitem__
list_ = super().__getitem__(key) …
▶ Local vars
During handling of the above exception ('myfile'), another exception occurred:
D:\omar\pythonProject\venv\lib\site-packages\django\core\handlers\exception.py, line 47, in inner
response = get_response(request) …
▶ Local vars
D:\omar\pythonProject\venv\lib\site-packages\django\core\handlers\base.py, line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) …
▶ Local vars
D:\omar\pythonProject\Dhb\views.py, line 5951, in index
cursor.execute('insert into images values(%s)', [request.FILES['myfile']]) …
▶ Local vars
D:\omar\pythonProject\venv\lib\site-packages\django\utils\datastructures.py, line 78, in __getitem__
raise MultiValueDictKeyError(key)
我试图将图像插入到 sqlite,但它没有用它总是给我错误
【问题讨论】:
标签: django django-models django-views django-forms django-templates