when i upload icon and image then error come
MultiValueDictKeyError at /product/create/
'icon'
Request Method: POST
Request URL: http://127.0.0.1:8000/product/create/
Django Version: 2.2a1
Exception Type: MultiValueDictKeyError
Exception Value:
'icon'
Exception Location: C:\Users\Rohit\Anaconda3\lib\site-packages\django-2.2a1-py3.7.egg\django\utils\datastructures.py in __getitem__, line 80
Python Executable: C:\Users\Rohit\Anaconda3\python.exe
Python Version: 3.7.0
def create(request):
if request.method == 'POST':
if request.POST['title'] and request.POST['body'] and request.POST['url'] and request.POST['icon'] and request.POST['image']:
product=Product()
product.title=request.POST['title']
product.body=request.POST['body']
if request.POST['url'].startswith('https//') or request.POST['url'].startswith('http//'):
product.url=request.POST['url']
else:
product.url= 'https//'+ request.POST['url']
product.image = request.FILES['image']
product.icon = request.FILES['icon']
product.pub_date=timezone.datetime.now()
product.hunter = request.user
product.save()
return redirect('home')
else:
return render(request, 'products/create.html',{'error': 'please fill all the detail'})