2

I was thinking something like this:

url = models.CharField(max_length=2047)

Is there a solution that would be more efficient for the ORM / SQL?

WSkinner
  • 2,147
  • 1
  • 19
  • 21

2 Answers2

5

You can use a URLField but it's just a subclass of CharField and thus defaults to 200 characters.

However IE8 & 9's limit for URL length is 2083 chars, Firefox, Opera, and Safari can handle at least 80,000 chars. I doubt you'll ever see a URL that long without a bunch of get data (like &whatever=1&whatelse=2...)

Community
  • 1
  • 1
JKirchartz
  • 17,612
  • 7
  • 60
  • 88
  • 1
    The browsers are 1 piece of that. The other is the servers. Here is a link to a recent change for asp.Net http://www.asp.net/whitepapers/aspnet4#0.2__Toc253429244. So, 200 is probably fine for 99% of inputs that you will get. If you need to change it, then use the max_length option. – David S Mar 02 '12 at 22:32
  • I agree. It's nice to see the upper limit though. – JKirchartz Mar 03 '12 at 04:08
0

Use URLField (or IPAddressField) for this. It is transformed to string by Django. URLField

Aleksej Vasinov
  • 2,662
  • 28
  • 29