Posted By

eternal_fame on 08/21/13


Tagged

templates unicode django slugify Russian unidecode


Versions (?)

Slugify russian symbols in Django templates


 / Published in: Django
 

slugification of russian symbols using unidecode in Django templates

  1. # in templatetags/my_tags.py
  2.  
  3. from django import template
  4. from unidecode import unidecode as _unidecode
  5.  
  6. register = template.Library()
  7.  
  8. @register.filter
  9. def unidecode(string):
  10. return _unidecode(string.lower().replace (" ", "_")).replace("'","") # last replace is unnecessary, but, for example, in links symbol ' looks awful
  11.  
  12. # in template
  13.  
  14. {% load my_tags %}
  15. {{ something|unidecode }}

Report this snippet  

You need to login to post a comment.