URLField Validation

447 views
Skip to first unread message

Matthew Pava

unread,
Sep 23, 2022, 3:58:55 PM9/23/22
to django-d...@googlegroups.com

Hello,

I ran into an issue with a models.URLField because it limits the size of the field to 200 characters. I find this too short to my use case. I have a valid URL to an external website (in academia), and it won’t fit in the Django URLField.

 

This took me down a rabbit hole and this very good answer on Stack Overflow:

https://stackoverflow.com/a/417184/603819

 

Summary:

  1. The HTTP protocol doesn’t place a limit on the number of characters.
  2. Modern browsers suggest not exceeding 2,000 characters.

 

There are other details, such as the domain name not exceeding 255 characters, but that is a different issue.

 

Why does Django impose such a limit on URLField? Could we increase it to, say, 2000 characters? Or even just remove the limitation on it?

Thanks,

Matthew

Ken Whitesell

unread,
Sep 23, 2022, 4:13:23 PM9/23/22
to Django developers (Contributions to Django itself)
That limit is a default setting. You're free to change it to whatever value you want in your models.
(See the docs for URLField)

Reply all
Reply to author
Forward
0 new messages