It's returning error when i use instance or without that in JsonResponse. Maybe JsonResponse cannot serialize data. The error is
Traceback (most recent call last): File "/Users/admin/Documents/Projects/food/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/Users/admin/Documents/Projects/food/venv/lib/python3.10/site-packages/django/utils/deprecation.py", line 138, in call response = self.process_response(request, response) File "/Users/admin/Documents/Projects/food/venv/lib/python3.10/site-packages/django/middleware/clickjacking.py", line 27, in process_response if response.get("X-Frame-Options") is not None: AttributeError: 'tuple' object has no attribute 'get'
I couldn't find source of error. I tried to solve that with helping google. But I did't find any exact solution. Yes tuple doesn't have a method get.
views.py
class CreateCategoryAjaxView(View):
def post(self, request, *args, **kwargs):
form = CategoryForm(request.POST, request.FILES)
if form.is_valid():
instance = form.save()
return JsonResponse(
{'is_success': True, 'id': instance.id, 'title': instance.title}),
return JsonResponse({'is_success': False, 'errors': form.errors})
forms.py
class CategoryForm(forms.ModelForm):
class Meta:
model = Category
fields = '__all__'
widgets = {
'title': forms.TextInput(
attrs={'placeholder': ' Пиццы...', 'class': 'form-control', 'id':
'id_category_title'}),
'image': forms.FileInput(attrs={'accept': 'image/*', 'id': 'id_category_image'}),
}