D
D
denislysenko2020-04-28 19:19:14
Django
denislysenko, 2020-04-28 19:19:14

I am making a website with Django. An error occurs when clicking the publish button. How to solve it?

here is the error
MultiValueDictKeyError at /publish
'secret'
Request Method: POST
Request URL: 127.0.0.1:8000/publish
Django Version: 3.0.5
Exception Type: MultiValueDictKeyError
Exception Value:
'secret'
Exception Location: /Library/Frameworks/Python.framework /Versions/3.8/lib/python3.8/site-packages/django/utils/datastructures.py in __getitem__, line 78
Python Executable: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
Python Version: 3.8 .2
Python Path:
['/Users/denislysenko/Downloads/coda/mysite1',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload',
'/Library/ Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages']
Server time: Tue, 28 Apr 2020 16:10:50 +0000

here is views.py

def publish(request):
if request.method == 'GET':
return render(request, 'publish.html')
else:
secret = print(request.POST['secret'])
name = print(request.POST['name'])
text = print(request .POST['text'])

publications_date.append({
'id': len(publications_date),
"name": name,
"date": datetime. now(),
"text": text
})

return redirect('/publications')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Miit, 2020-04-28
@denislysenko

You are trying to call a value on the secret key, which is not present in the request object. Check your form and the inputs specified in it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question