Does any one know how to get rid of the 'http://' prefix in Django urlfield.
I mean when we define a field as urlfield and try to enter a url to it, django will automatically add 'http://' prefix to it if no schema provide. I don't want that prefix.
I try to remove it under clean_field and clean method. It doesn't work.
I dig into the source code. I saw that django add 'http://' in 'to_python' method under UrlField class.
Is there any way to override it to get rid of 'http://'?
Without a scheme prefix, a string can't be a true URL, and accordingly, the
URLField
won't support it.However, the
URLField
is pretty much just aCharField
with aURLValidator
, so if you write a newSchemelessURLValidator
(derived from the built-in one) and add that to a normalCharField
, that should get you where you want to go.In fact, your new validator could be as simple as