Skip to content

HiddenField shows up in the HTML form of the web browsable API page #2410

@lgp171188

Description

@lgp171188

I have a model with a foreign key reference to the User model called 'user'. In my serializer class, which is a sub-class of ModelSerializer, I have overridden the default field created by ModelSerializer and set it to:

user = serializers.HiddenField(default=serializers.CurrentUserDefault())

When displaying the fields in the API response, this field is indeed hidden, but in the web browsable API page, the HTML form shows a textbox for the user field which is supposed to be hidden.

Here is my serializer definition:

class CategorySerializer(serializers.ModelSerializer):
    user = serializers.HiddenField(default=serializers.CurrentUserDefault())
    class Meta:
        model = Category
        fields = ('name', 'description', 'created', 'modified','user')

Please see the screenshot illustrating the HTML form with an input for the hidden field.

hiddenfield shown in html form

I am totally new to Django REST Framework, so sorry if I haven't RTFM and raised this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy