Django 1.9 URLField removing the necessary http:// prefix
<p>I've seen a bunch of questions about this, but havent found an answer yet. </p>

<p>This is my models:</p>

<pre><code>class UserProfile(models.Model):
    user = models.OneToOneField(User)
    .
    .
    . 
    website = models.URLField(max_length=100, blank=True, null=True)
</code></pre>

<p>and my forms.py:</p>

<pre><code>class UserProfileForm(forms.ModelForm):
    class Meta:
        model = UserProfile
        fields = ('website')

    def clean_website(self):
        website = self.cleaned_data['website']
        if website and not website.startswith('http://'):
            website = 'http://' + website
            return website

    # def clean(self):
    #     cleaned_data = self.cleaned_data
    #     url = cleaned_data.get('url')
    #
    #     if url and not url.startswith('http://'):
    #         url = 'http://' + url
    #         cleaned_data['url'] = url
    #         return cleaned_data
</code></pre>

<p>I've tried to clean the web address, but I the way django is set up I dont have an opportunity to get to the clean functions. 
<a href="http://i.stack.imgur.com/jSIYV.png" rel="nofollow"><img src="http://i.stack.imgur.com/jSIYV.png" alt="enter image description here"></a></p>

<p>How can I change Django to allow user the ability to not put in the http(s):// prefix?</p>

<p>I don't want to initialize it with this type of code:</p>

<pre><code>url = forms.URLField(max_length=200, help_text="input page URL", initial='http://')
</code></pre>

<p>I've seen this thread:<a href="http://stackoverflow.com/questions/16307055/django-urlfield-http-prefix">django urlfield http prefix</a>
But admittedly am not sure where to put it to see if it even works.</p>

<p>This validation isn't being done by Django, but by your browser itself. You can disable that by putting <code>novalidate</code> in the surrounding <code>&lt;form&gt;</code> element.</p>

python django django-models django-forms django-urls