MultiValueDictKeyError at / 'name'

введите описание изображения здесь

я просто хочу получить данные с моего сайта и записать их в мою базу данных django

вот мой код views.py :

 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)

Если параметры могут быть пустыми (не передаются), используйте 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)

Если параметры не должны быть пустыми, проблема в том, как клиент делает запрос.

Вернуться на верх