class CreateUserResource(ModelResource):
class Meta:
allowed_methods = ['post']
object_class = User
authentication = ApiKeyAuthentication()
authorization = DjangoAuthorization()
include_resource_uri = False
fields = ['username']
models.signals.post_save.connect(create_api_key, sender=User)
def obj_create(self, bundle, request=None, **kwargs):
username, password = bundle.data['username'], bundle.data['password']
#try:
bundle.obj = User.objects.create_user(username, '', password)
#except IntegrityError:
#raise BadRequest('That username already exists')
#return bundle
我正在使用此资源来创建新用户。但为了做到这一点,我需要一个 api_key。由于我是匿名的,我怎样才能获得 api_key?