I have a model in the django backend with validators, select fields, etc. I would like to convey it in order to respond and display it. First, is it possible? I would like to get it completely using validators, but just the html is still great. The reason of that:
- Avoid double permanent ads on the front and back. For example, select options: "man", "woman", "???" must be on the backend for validation and validation for display and validation.
- Building the full html in the interface for the form again, despite the fact that all this can also be easily created by django. The main problem is again selecting options with many different custom values.
There is a package called drf-braces that has a FormSerializer, but it seems to have a problem, I constantly get the error 500 "is not a JSON serializable error," for example:
name_or_event = CharFormSerializerField(error_messages={u'required': <django.utils.functional.__proxy__ object>}, help_text='', initial=None, label='Name', required=True, validators=[]) is not JSON serializable
This is a drf-based serializer, as shown in the drf-braces serialization example:
from drf_braces.serializers.form_serializer import FormSerializer from myapp.forms import SignupDataForm class MySerializer(FormSerializer): class Meta(object): form = SignupDataForm
and a rest-auth RegisterView - based API view:
from myapp.serializers import MySerializer class TestView(RegisterView): permission_classes = (AllowAny,) allowed_methods = ('GET', ) serializer_class = MySerializer def get(self, *args, **kwargs): serializer = self.serializer_class() return Response({'serializer': serializer}, status=status.HTTP_200_OK)
If I open the url assigned by TestView in the browser, I will see the form fields. But when loading ajax from the reaction, I get 500 with a "not JSON serializable error" above. The call is made from the React.component constructor, as shown below. I am not saying that he displayed the field correctly while I tried to print the answer to the console and see what error it was giving, but it does not get to this:
loadUserDetail() { this.serverRequest = $.get("myUrl", function (result) { console.log(result); this.setState({ username: result.name_or_event, email: result.email }); }.bind(this)); }
Any other ideas how to do this? I completely disagree with my approach, right ?:-)