简体   繁体   中英

How can i allow both IP Address and URL in django field?

I want to allow both flutterdemo.hp.com and 12.135.720.12 in django field.

This is what i tried.

from rest_framework import serializers, viewsets
from django.core.validators import URLValidator

class FlutterSerializer(serializers.HyperlinkedModelSerializer):
    fqdn_ip = serializers.CharField(max_length = 100, validators =[URLValidator])

But it is allowing all the text and just working as CharFiled. URLField is treating "flutterdemo.hp.com" as invalid.

How can i achieve this? Thanks,

You can use this third-party library for Validating URL and IP.

Validate Ipv4 Ip here

Validate Ipv6 Ip here

Validate Url here

After validate you can save with CharField

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM