FTP prefic in URL field

52 views
Skip to first unread message

ggavy

unread,
Jul 15, 2011, 9:21:14 AM7/15/11
to Django users

Hi all,
I'm using a URLField in a model and form. However the form
validation for this does not accept 'ftp://' type prefixes. What are
my options here? Do I need to write a custom field or is it possible
to modify the 'validate' method on the field itself so that it
includes the default URL requirements and the ftp prefix. My limited
knowledge in this stuff tells me that this latter one is not possible?
Any advice?

Thanks

Tim Shaffer

unread,
Jul 15, 2011, 9:52:08 AM7/15/11
to django...@googlegroups.com
It looks like the URLValidator should in fact accept ftp:

https://github.com/django/django/blob/master/django/core/validators.py#L46

What's the specific error you're getting?

ggavy

unread,
Jul 15, 2011, 10:02:54 AM7/15/11
to Django users

Hi Tim,
I'm getting the 'Enter a valid URL.' error returned. I am however
using Django 1.1, and thought that was the issue (I'm not sure where
to look for the validator.py in this older version, but I think Iread
somewhere that ftp wasn't in the regex at that version). Migrating to
1.2 isn't practical at the moment.

G


On Jul 15, 2:52 pm, Tim Shaffer <timshaf...@me.com> wrote:
> It looks like the URLValidator should in fact accept ftp:
>
> https://github.com/django/django/blob/master/django/core/validators.p...

Tim Shaffer

unread,
Jul 15, 2011, 10:12:51 AM7/15/11
to django...@googlegroups.com
Yeah, it doesn't look like 1.1 allowed for ftp protocol:

https://github.com/django/django/blob/1.1.X/django/forms/fields.py#L545

Best bet might be to create your own URLField class and overwrite the __init__ method to use your own regular expression. Kind of a pain. It's a little easier in future versions because you can just overwrite the validator instead of the whole field.

ggavy

unread,
Jul 18, 2011, 4:08:49 AM7/18/11
to Django users
Thanks Tim,
I kinda guessed that would be the case. Thanks for the advice.

G
Reply all
Reply to author
Forward
0 new messages