Advantages to using URLField over TextField?

后端 未结 3 648
后悔当初
后悔当初 2021-02-03 18:07

As I understand it you should always use a TextField for a variable length string when your using a PostgreSQL database because the speed difference between a

3条回答
  •  庸人自扰
    2021-02-03 18:17

    https://docs.djangoproject.com/en/dev/ref/models/fields/#urlfield Of course you can use CharField/TextField but handling user input and be sure whatever user enters is up-to you.

    From the source code:

    # As with CharField, this will cause URL validation to be performed

    If you see the URLField source code you will find it's actually a CharField with URL validator.

    Also there is other ready to use fields such as EmailField, ImageField, *Field!

提交回复
热议问题