1 2 3 4 5 6 7 8 9 10 11 12 | def urlsafestring(string): from string import strip, rstrip, lstrip, replace string = str(string) badchars = [".",",","+","=","%","#","!","@","$","^","*","(",")","\\","/","\"","[","]","{","}","|","'","?"] for b in badchars: string = replace(string, b, "") string = rstrip(string) string = lstrip(string) string = replace(string, "-", "_") string = replace(string, " ", "_") string = replace(string, "__", "_") return string |
Comments
this might be better:
Example:
#
Isn't this essentially the same as Django's
slugifyfilter?#