0

I would like to know if someone here could help me out finding a way to "filter" URLs inside block of texts, comments for example. I wish to be able to "Block" the submitting of such comments on my website.

So for example, if someone would type blablabla http://bla.com, the application would deny the user from submitting its entry. I was able to make a very "homemade" script which looked inside the text to find stuff like www. , .com, http etc. However it doesn't feel very solid at all.

Thanks !

4

1 回答 1

1

您可以执行以下操作:

simple_url_re = re.compile(r'^(https?)?://\[?\w', re.IGNORECASE)
simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|edu|gov|int|mil|net|org)$', re.IGNORECASE)

if simple_url_re.match(text) or simple_url_2_re.match(text):
    raise ValidationError

您可以使用 django 的urlize获取想法

于 2013-05-23T15:17:47.460 回答