'MultiValueDictKeyError at / 'name'
i just want to fetch the data from my website and record it to my django databae
this my views.py code :
def index(request):
feature1 = Feature.objects.all()
Appnt = Appointment.objects.all()
if request.method == 'GET':
Appnt.name = request.GET['name']
Appnt.email = request.GET['email']
Appnt.phone = request.GET['phone']
Appnt.Adate = request.GET['date']
Appnt.Dept = request.GET['department']
Appnt.Doc = request.GET['doctor']
Appnt.message = request.GET['message']
contaxt = {
'feature1' : feature1,
'Appointment' : Appnt
}
return render(request, 'index.html', contaxt)
Solution 1:[1]
If the parameters can be blank (not passed), use get:
def index(request):
feature1 = Feature.objects.all()
Appnt = Appointment.objects.all()
if request.method == 'GET':
Appnt.name = request.GET.get('name')
Appnt.email = request.GET.get('email')
Appnt.phone = request.GET.get('phone')
Appnt.Adate = request.GET.get('date')
Appnt.Dept = request.GET.get('department')
Appnt.Doc = request.GET.get('doctor')
Appnt.message = request.GET.get('message')
context = {
'feature1' : feature1,
'Appointment' : Appnt
}
return render(request, 'index.html', context)
If the parameters should not be blank, the problem is how the client makes the request.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | RedWheelbarrow |
