django-rest-framework

Django REST Framework NOT NULL constraint failed

ぃ、小莉子 提交于 2021-02-10 14:56:12
问题 when I try to create a new Post by posting the following JSON: { "text": "test", "location": 1 } I get the following error: NOT NULL constraint failed: grapevineapp_post.location_id models.py: class Location(models.Model): name = models.CharField(max_length=80) created = models.DateTimeField(auto_now_add=True) def __str__(self): return self.name class Post(models.Model): text = models.CharField(max_length=512) owner = models.ForeignKey('auth.User', related_name='posts', on_delete=models

How to get array of values from checkbox form Django

狂风中的少年 提交于 2021-02-10 09:31:49
问题 I have HTML form like this: <p>Models Sizes IDs:</p> <input type="checkbox" name="model_size_ids[]" value="1">XS</input> <input type="checkbox" name="model_size_ids[]" value="2">S</input> <input type="checkbox" name="model_size_ids[]" value="3">M</input> <input type="checkbox" name="model_size_ids[]" value="4">L</input> <button>Submit</button> I'm trying to receive an array of checked values on server side in my View : size_ids = request.data['model_size_ids[]'] But, I can extract only one

How to get array of values from checkbox form Django

霸气de小男生 提交于 2021-02-10 09:26:48
问题 I have HTML form like this: <p>Models Sizes IDs:</p> <input type="checkbox" name="model_size_ids[]" value="1">XS</input> <input type="checkbox" name="model_size_ids[]" value="2">S</input> <input type="checkbox" name="model_size_ids[]" value="3">M</input> <input type="checkbox" name="model_size_ids[]" value="4">L</input> <button>Submit</button> I'm trying to receive an array of checked values on server side in my View : size_ids = request.data['model_size_ids[]'] But, I can extract only one

Nested validation in Django Rest Framework

倖福魔咒の 提交于 2021-02-10 06:54:41
问题 Using django rest framework I want to validate fields. Correct input request: { test_field_a: {test_field_c: 25}, test_field_b: {} } My serializers.py (I don't have any associated models and the models.py itself): from rest_framework import serializers class TestSerializer(serializers.Serializer): test_field_a = serializers.JSONField(label='test_field_a', allow_null=False, required=True) test_field_b = serializers.JSONField(label='test_field_b', required=True) test_field_c = serializers

How to pass the user token for API testing in django rest framework?

梦想与她 提交于 2021-02-10 03:26:53
问题 I'm writing some tests to check the connection to my API. I've put in place identification via tokens and I am successful with retrieving a token for a specific test user with : token = Token.objects.get(user__username='testuser') What I'm struggling with is to use that token to create a successful API request as this one : client = APIClient(HTTP_AUTHORIZATION='Token ' + token.key) response = client.get('/patientFull/1/',headers={'Authorization': 'Token ' + token.key}) I have been looking at

How to pass the user token for API testing in django rest framework?

不羁岁月 提交于 2021-02-10 03:21:33
问题 I'm writing some tests to check the connection to my API. I've put in place identification via tokens and I am successful with retrieving a token for a specific test user with : token = Token.objects.get(user__username='testuser') What I'm struggling with is to use that token to create a successful API request as this one : client = APIClient(HTTP_AUTHORIZATION='Token ' + token.key) response = client.get('/patientFull/1/',headers={'Authorization': 'Token ' + token.key}) I have been looking at

How to pass the user token for API testing in django rest framework?

。_饼干妹妹 提交于 2021-02-10 03:19:24
问题 I'm writing some tests to check the connection to my API. I've put in place identification via tokens and I am successful with retrieving a token for a specific test user with : token = Token.objects.get(user__username='testuser') What I'm struggling with is to use that token to create a successful API request as this one : client = APIClient(HTTP_AUTHORIZATION='Token ' + token.key) response = client.get('/patientFull/1/',headers={'Authorization': 'Token ' + token.key}) I have been looking at

How to pass the user token for API testing in django rest framework?

余生长醉 提交于 2021-02-10 03:18:52
问题 I'm writing some tests to check the connection to my API. I've put in place identification via tokens and I am successful with retrieving a token for a specific test user with : token = Token.objects.get(user__username='testuser') What I'm struggling with is to use that token to create a successful API request as this one : client = APIClient(HTTP_AUTHORIZATION='Token ' + token.key) response = client.get('/patientFull/1/',headers={'Authorization': 'Token ' + token.key}) I have been looking at

How to pass the user token for API testing in django rest framework?

∥☆過路亽.° 提交于 2021-02-10 03:18:35
问题 I'm writing some tests to check the connection to my API. I've put in place identification via tokens and I am successful with retrieving a token for a specific test user with : token = Token.objects.get(user__username='testuser') What I'm struggling with is to use that token to create a successful API request as this one : client = APIClient(HTTP_AUTHORIZATION='Token ' + token.key) response = client.get('/patientFull/1/',headers={'Authorization': 'Token ' + token.key}) I have been looking at

allow post requests in django REST framework

独自空忆成欢 提交于 2021-02-09 11:12:38
问题 I am creating a simple rest api using django REST framework. I have successfully got the response by sending GET request to the api but since I want to send POST request, the django rest framework doesn't allow POST request by default. As in image(below) only GET,HEAD, OPTIONS are allowed but not the POST request The GET and POST methods inside of views.py from django.shortcuts import render from rest_framework.views import APIView from rest_framework.response import Response from profiles