[Django]-How can I verify if a URLField is from a desired domain in Django?

3👍

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
👤second

0👍

I think it would be best to use some kind of regular expressions (regex) in your clean_link method. I don’t know about it in detail, but the urparse module mentioned by @second may be good, or you can just use the re module. Your current overall strategy seems fine though.

Leave a comment