I am using Django Rest Framework. And for documentation I am using drf-spectacular.
But the problem I am facing is that when I am trying to submit using form, I can not submit. But I can submit using JSON type normally.
This Does not Work:
This Works:
How can I make the form to work? It does not even let me submit the form. Also, How can I make the profile_pic as filefield?
Below is my code:
settings.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
'DEFAULT_PARSER_CLASSES': [
'rest_framework.parsers.JSONParser',
'rest_framework.parsers.FormParser',
'rest_framework.parsers.MultiPartParser',
'rest_framework.parsers.FileUploadParser',
],
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}
SPECTACULAR_SETTINGS = {
'TITLE': 'Your Project API',
'DESCRIPTION': 'Your project description',
'VERSION': '1.0.0',
}
serializers.py
from rest_framework import serializers
from app_restaurant import models
class RestaurantSerializer(serializers.ModelSerializer):
"""
Restaurant Create Serializer
"""
class Meta:
model = models.Restaurant
fields = '__all__'
extra_kwargs = {
'slug': {'read_only': True},
}
views.py
from rest_framework import generics
from app_restaurant import serializers, models
from app_user import apipermissions
# Create your views here.
class RestaurantCreateView(generics.CreateAPIView):
"""
Restaurant Creation View
"""
permission_classes = [apipermissions.IsOwner]
serializer_class = serializers.RestaurantSerializer
queryset = models.Restaurant.objects.all()


Same here with application/x-www-form-urlencoded. While it works from curl. I am thinking of dropping the application/x-www-form-urlencoded and multipart/form-data options - as I only need JSON - entirely out of the html using css or javascript if I can..