django-rest-framework

Data is not being saved as Encrypted data django

跟風遠走 提交于 2021-02-05 10:39:42
问题 till now I tried more then 6 plugins and quite frustrate now. Now using this one cryprtography everything is fine and done accordingly but when I save data in model manager like this def create_user(self, email, password, **extra_fields): user = self.model(email=email, **extra_fields) user.test_field = 'new.user@oc.com' user.save(using=self._db) return user it saving data normally not encrypted My model is like class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField(max

django.db.migrations.exceptions.NodeNotFoundError: Migration accounts.0001_initial dependencies reference nonexistent parent node

耗尽温柔 提交于 2021-02-04 21:36:15
问题 I'm trying to deploy my project on heroku ,i'm using django 3.1 and i'm unable to do that. I'm getting error due to migrations. Please i humble request you to give some time to this question to resolve this problem. Whenever i run the command heroku run python manage.py migrate ,it gives following traceback. Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "/app/.heroku/python/lib

Django rest_framework custom error message

廉价感情. 提交于 2021-02-04 19:50:36
问题 I have a API endpoint where it will do input validation using rest_framework's serializer.is_valid() where it will return custom error message and response. serializer = FormSerializer(data=data) if not serializer.is_valid(raise_exception=False): return Response({"Failure": "Error"}, status=status.HTTP_400_BAD_REQUEST) Is it possible to populate validation errors without using the generic response provided by raise_exception=True ? I am trying to avoid using the generic response as it will

Django rest_framework custom error message

陌路散爱 提交于 2021-02-04 19:50:26
问题 I have a API endpoint where it will do input validation using rest_framework's serializer.is_valid() where it will return custom error message and response. serializer = FormSerializer(data=data) if not serializer.is_valid(raise_exception=False): return Response({"Failure": "Error"}, status=status.HTTP_400_BAD_REQUEST) Is it possible to populate validation errors without using the generic response provided by raise_exception=True ? I am trying to avoid using the generic response as it will

Why do you need to use Django REST API?

早过忘川 提交于 2021-02-04 19:09:43
问题 Why do you need to use Django REST framework to make an API? Can't you just create routes like /api/createuser with normal Django and handle all of the backend logic from there as you would normally? 回答1: You do not NEED to use Django REST framework to make an API But if you are going to make a decent REST API in Django, DRF is a framework on top of Django that helps you building an API with following features: Web browseable API, documentation autogeneration Generic views auto building from

Django-Rest-Framework AssertionError HTTPresponse Expected

廉价感情. 提交于 2021-02-04 17:11:29
问题 When i do the following command over Terminal using curl curl -X POST http://myuser:mypassword@myweb.com:8000/call/make-call/ -d "tutor=1&billed=1" I get the following error AssertionError at /call/make-call/ Expected a Response , HttpResponse or HttpStreamingResponse to be returned from the view, but received a <type 'NoneType'> My views.py is @api_view(['GET', 'POST']) def startCall(request): if request.method == 'POST': serializer = startCallSerializer(data=request.DATA) if serializer.is

Django-Rest-Framework AssertionError HTTPresponse Expected

僤鯓⒐⒋嵵緔 提交于 2021-02-04 17:11:12
问题 When i do the following command over Terminal using curl curl -X POST http://myuser:mypassword@myweb.com:8000/call/make-call/ -d "tutor=1&billed=1" I get the following error AssertionError at /call/make-call/ Expected a Response , HttpResponse or HttpStreamingResponse to be returned from the view, but received a <type 'NoneType'> My views.py is @api_view(['GET', 'POST']) def startCall(request): if request.method == 'POST': serializer = startCallSerializer(data=request.DATA) if serializer.is

serialize a datetime as an integer timestamp

笑着哭i 提交于 2021-02-04 11:23:48
问题 I would like for django rest to not convert my DateTime model field into a string date represtation when serializing it. response_date = serializers.DateTimeField(source="updated_at") I would like this to come out as 1411880508 and not "2014-09-28T05:01:48.123" 回答1: You'll want to write a custom serializer field, like so: class TimestampField(serializers.Field): def to_native(self, value): epoch = datetime.datetime(1970,1,1) return int((value - epoch).total_seconds()) To support write

serialize a datetime as an integer timestamp

佐手、 提交于 2021-02-04 11:23:26
问题 I would like for django rest to not convert my DateTime model field into a string date represtation when serializing it. response_date = serializers.DateTimeField(source="updated_at") I would like this to come out as 1411880508 and not "2014-09-28T05:01:48.123" 回答1: You'll want to write a custom serializer field, like so: class TimestampField(serializers.Field): def to_native(self, value): epoch = datetime.datetime(1970,1,1) return int((value - epoch).total_seconds()) To support write

i am tring to write a customr permissions class to add permissions for the user to rate the movie once per user

非 Y 不嫁゛ 提交于 2021-01-29 22:31:30
问题 here i am trying to add custom permissions 1.user can rate the movie once 2.Users can add a movie and other people, except the creator, can rate it. i have written the custom permission class in the permission.py but still it not doing what i want but it is going wrong .can please some help one models.py from django.contrib.auth.models import User from django.core.validators import MinValueValidator, MaxValueValidator class Movie(models.Model): title = models.CharField(max_length=128)