![]() Return render(request, 'frontend/index. This is the view of the form page itself def formsPage(request): I want upon posting data, the submittedUser field is the loggedin user (er in normal django view) but when I post data it gives me error obj = self.model(**kwargs)ĮError: Cannot assign "": "entry.submittedUser" must be a "User" instance. Let’s create a new Django project with command: django-admin startproject bzkRestApis. For example the request.META and ssion dictionaries are available as normal. To install this package, run command: pip install djangorestframework. As REST frameworks Request extends Djangos HttpRequest, all the other standard attributes and methods are also available. Return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) Django REST framework helps us to build RESTful Web Services flexibly. Return Response(serializer.data,status=status.HTTP_201_CREATED) Serializer = EntryFormSerializer(data=data) Parser_classes = [MultiPartParser, FormParser, post(self, request, format=None): Views.py: class EntryFormViewSet(APIView):Īuthentication_classes = Serializers.py: class EntryFormSerializer(serializers.ModelSerializer): For example you can use the Mobheader extension. SubmittedUser = models.ForeignKey('User',blank=True,null=True, on_delete=models.CASCADE, related_name='submitteduser') 1 Answer Sorted by: 1 Its happening because you are using permissionclasses IsAuthenticated in your QuestionListView You must provide the auth token. I have a form that contains a field called submittedUser that I want it to define the user that posted the form Django REST framework is based on Django’s class-based views, so it’s an excellent option if you’re familiar with Django. I am working on an app using Django and React and I use DRF to create APIs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |