【发布时间】:2023-01-05 18:16:46
【问题描述】:
我收到此错误“WSGIRequest”对象在我的代码中没有属性“get” 下面是我在 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)
下面是我在 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
如何解决这个问题? chatgpt 没有帮助,所以我在这里问
【问题讨论】: