B
B
Black back2020-04-16 09:10:52
Django
Black back, 2020-04-16 09:10:52

Why is this error "raise MultiValueDictKeyError(key) django.utils.datastructures.MultiValueDictKeyError: 'file'" coming out?

Please tell me what is the problem

def signupp(request):
    if request.method == 'POST':
                user = User.objects.create_user(username=request.POST['name'], password=request.POST['pin'])
                number = request.POST['number']
                fname = request.POST['fname']
                lname = request.POST['lname']
                address = request.POST['address']
                birtday = request.POST['birtday']
                passport = request.POST['passport']
                number_pass = request.POST['number_pass']
                body_pass = request.POST['body_pass']
                file = request.POST['file']
                role = request.POST['role']
                new = Register(number=number,fname=fname,lname=lname,address=address,birtday=birtday,passport=passport,number_pass=number_pass,
                               body_pass=body_pass,file=file,role=role)
                new.save()
                print('saved')
                auth.login(request, user)
                return HttpResponse("Signed Up")
    else:
        return render(request, 'registration/registration.html')


<form  action="{% url 'sign' %}" method="post" enctype="multipart/form-data">
                {% csrf_token %}
                <input type="text" name="number">
                <input type="text" name="fname">
                <input type="text" name="name">
                <input type="text" name="lname">
                <input type="text" name="address">
                <input type="date" name="birtday">
                <input type="text" name="passport">
                <input type="text" name="number_pass">
                <input type="text" name="body_pass">
               <input type="password" name="pin" placeholder="pin">
                <input type="file" name="file">
                <input type="text" name="role">
<button type="submit" value="Signup" class="btn btn-outline-primary btn-block mb-5 ">Добавить</button>
      </form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2020-04-16
@deepblack

Replace

request.POST['name']
# на
request.POST.get('name')

etc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question