简体   繁体   中英

DJANGO 'WSGIRequest' object has no attribute 'get'

I get this error 'WSGIRequest' object has no attribute 'get' in my code Below is my function in views.py

def user_attendance(request):
   # Get the attendance records for the current user
    attendance_records = Attendance.objects.filter(user=request.user)
 
    # Create a form instance
    form = CompensationRequestForm()

   # Check if the form has been submitted
    if request.method == 'POST':
        # Bind the form with the POST data
        form = CompensationRequestForm(request.POST)
        # Check if the form is valid
        if form.is_valid():
            # Save the form data
            form.save()
            # Redirect to the user_attendance view
           return redirect('user_attendance')
    context = {'attendance_records': attendance_records, 'form': form}

    # Render the template with the attendance records and form
    return render(request, 'user_attendance.html', context)

and below is my form in forms.py

class CompensationRequestForm(forms.Form):
    date = forms.DateField()
    reason = forms.CharField(widget=forms.Textarea)
    def save(self):
        # Save the form data to the database
        pass

how to fix this? chatgpt didnt help, so i asked here

instead of this form = CompensationRequestForm(request.POST) try this way:

form = CompensationRequestForm(data=request.POST)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM