我将 all_auth 和 rest_auth 与 Angular 一起使用。我有一个名为 Campaign 的模型
class Campaign(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=100)
hashtag = models.CharField(max_length=20)
message = models.CharField(null=True, blank=True, max_length=100)
sale_limit = models.IntegerField(null=True, blank=True)
start_date = models.DateField(null=True, blank=True)
expiry_date = models.DateField(default=now_plus_30)
product_url = models.CharField(max_length=100)
created_at = models.DateTimeField(default=datetime.now, blank=True)
modified_at = models.DateTimeField(auto_now_add=True, blank=True)
user = models.ForeignKey(User, unique=False)
def __str__(self): # __unicode__ on Python 2
return self.name
并认为
class ListCreateCampaign(APIView):
"""
List all Campaigns or create one.
"""
def post(self, request, format=None):
serializer = CampaignSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
我不想通过 API 传递 user_id,如何获取用户详细信息并将其注入 request.data