I have a URLField in my application form and I would like to check if the given URL is from www.domain.com.
Right now I'm using this solution in the clean method of the field, but I think that is not the best one...
def clean_link(self):
link = self.cleaned_data['link']
if 'domain.com' not in link:
raise forms.ValidationError('You only can add a domain.com URL.')
return link
For example, if I enter http://www.thisismydomain.com would be correct. Any other solution?
Thank you very much.
you might want to have a look at the urlparse module, to avoid misses like
>>> 'good_domain.com' in 'http://evildomain.com/mylink#good_domain.com'
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With