小编tra*_*ash的帖子

如何动态地将EC2 IP地址添加到Django ALLOWED_HOSTS

我们最近更改了部署策略以使用AWS自动扩展组.

我们在生产中遇到的一个问题是新创建的EC2.
我们的申请开始返回:

Invalid HTTP_HOST header: 
    <ip_address>. You may need to add <ip_address> to ALLOWED_HOSTS`
Run Code Online (Sandbox Code Playgroud)

因为这些EC2不在原来的Django中ALLOWED_HOSTS.

每个新创建的EC2都必须重新部署是没有意义的; 这与"汽车规模"的意义相矛盾.
此外,出于安全原因,我们不希望使用通配符或IP范围.

我们能做什么?

python django amazon-ec2 amazon-web-services

11
推荐指数
2
解决办法
1513
查看次数

在创建新用户之前检查用户是否存在 djangorestframework

到目前为止我有 - >

序列化器:

class UserSerializer(serializers.ModelSerializer):
    """Serializer to map the model instance into json format."""
    class Meta:
        """Map this serializer to a model and their fields."""
        model = User
        fields = ('id','username', 'mobile', 'password', 
                  'first_name','last_name','middle_name', 
                  'profile_pic','short_bio','friends_privacy',
                  'address_1','address_2','city',
                  'state','country','pin','verification_code',
                  'is_active','is_blocked','is_reported',
                  'date_created','date_modified')
        extra_kwargs = {'password': {'write_only': True}}
        read_only_fields = (
            'date_created', 'date_modified',
            'is_staff', 'is_superuser', 'is_active', 
            'date_joined',)
    def create(self, validated_data):
        mobile_ = validated_data['mobile']
        password_ = validated_data['password']
        username_ = validated_data['username']
        motp = self.context['request'].GET['motp']
        eotp = self.context['request'].GET['eotp']
        email_ = self.context['request'].GET['email']
        mflag = api.views.checkOTP_(mobile_,motp)
        eflag = …
Run Code Online (Sandbox Code Playgroud)

django django-views python-2.7 django-serializer django-rest-framework

3
推荐指数
2
解决办法
3402
查看次数