'How to render a new user registration form from a model ViewSet in Django Rest frame work
class RegisterViewSet(viewsets.ModelViewSet):
http_method_names = ["post"]
permission_classes = (AllowAny,)
serializer_class = RegisterSerializer
renderer_classes = [TemplateHTMLRenderer]
template_name = "api/authentication/template/authentication/register.html"
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
user = serializer.save()
return Response(
{
"success": True,
"userID": user.id,
"msg": "The new user is successfully registered",
"serializer":serializer,
"form": UserRegisterForm
},
status=status.HTTP_201_CREATED,
)
I just want to render a form to display in HTML. Basically, how to render a form from a model viewset from django rest framework.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|