Opened 9 years ago

Closed 6 years ago

#5331 closed (fixed)

URLField should add http:// if no scheme given

Reported by: Chris Beaven Owned by: nobody
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


The usual scheme for a URLField is http://. You're average user will often not enter the scheme of their URL so the clean method should just prepend 'http://' if no scheme was given.

Attachments (2)

urlfield.patch (548 bytes) - added by Chris Beaven 9 years ago.
urlfield.2.patch (1.7 KB) - added by Chris Beaven 9 years ago.
with tests

Download all attachments as: .zip

Change History (7)

Changed 9 years ago by Chris Beaven

Attachment: urlfield.patch added

comment:1 Changed 9 years ago by Chris Beaven

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedDesign decision needed

Makes sense to me, but I'll pass it past the core developers.

Changed 9 years ago by Chris Beaven

Attachment: urlfield.2.patch added

with tests

comment:2 Changed 9 years ago by Simon G. <dev@…>

Triage Stage: Design decision neededReady for checkin

Ready to go.

comment:3 Changed 9 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [6173]) Fixed #5331 -- Modified newforms URLField to prepend http:// if no protocol is specified by the user. Thanks, SmileyChris?.

comment:4 Changed 6 years ago by Adam Alton

Resolution: fixed
Status: closedreopened

django.db.models.URLField doesn't have a custom 'formfield' method, and so by default it uses django.forms.CharField as its form field. And so django.forms.URLField never even gets used, so the patch submitted above is currently not having any effect (Django 1.3 alpha).

It needs a 'formfield' method adding to django.db.models.URLField...

class URLField:
    def formfield(self, **kwargs):
        if 'form_class' not in kwargs:
            kwargs['form_class'] = forms.URLField
        return super(URLField, self).formfield(**kwargs)
Last edited 6 years ago by Adam Alton (previous) (diff)

comment:5 Changed 6 years ago by Russell Keith-Magee

Has patch: unset
Resolution: fixed
Status: reopenedclosed
Triage Stage: Ready for checkinAccepted

@adamalton -- I don't know what code you're looking at, but URLField *does* have a custom formfield method, there is a unit test validating that http prefixing works as intended, and a quick test verifies that the field is working as intended.

Note: See TracTickets for help on using tickets.
Back to Top