Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting error with django slugify

I am trying this

from django.utils.text import slugify

In [8]: mystr = "This is john"

In [9]: slugify(mystr)

and i am getting this error

TypeError: must be unicode, not str

if i use this

from django.template.defaultfilters import slugify then it works but it does not chnage underscores to hyphens and if i have dots it simple removes it

like image 216
fdsgds Avatar asked Jul 29 '13 04:07

fdsgds


1 Answers

This is because slugify() expects a unicode object.

The easiest way to solve it is passing the string as a unicode object

mystr = u'This is John'

or

mystr = unicode('This is John')
>> u'This is John'
like image 132
Henrik Andersson Avatar answered Oct 27 '22 22:10

Henrik Andersson