推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
yanng
V2EX  ›  Python

求助 - 怎样让 django 的 slugfield 支持中文?

  •  
  •   yanng · Dec 20, 2011 · 9149 views
    This topic created in 5400 days ago, the information mentioned may be changed or developed.
    6 replies  •  1970-01-01 08:00:00 +08:00
    vicalloy
        1
    vicalloy  
       Dec 20, 2011
    用普通的charfield,没必要一定用slug
    ywjno
        2
    ywjno  
       Dec 20, 2011
    用encode的方式,
    不光是中文,各种不在asc码上的文字都能搞定了
    yanng
        3
    yanng  
    OP
       Dec 20, 2011
    @reus 谢谢,我去看看
    yanng
        4
    yanng  
    OP
       Dec 20, 2011
    @ywjno encode decode和不这样做直接显示汉字,在SEO或者其他方面有没有什么区别?
    lueo
        6
    lueo  
       Jul 17, 2012   ❤️ 1
    这个实现非常完整,也很稳定,针对django写的,运用的是undecode,运作如下:

    # -*- coding: utf-8 -*-
    from uuslug import uuslug as slugify
    s = u"这就是一串中文字,你看得懂吗?"
    print slugify(s)
    >>> zhe-jiu-shi-chuan-zhong-wen-zi-ni-kan-de-dong-ma

    https://github.com/un33k/django-uuslug
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   756 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:37 · PVG 05:37 · LAX 14:37 · JFK 17:37
    ♥ Do have faith in what you're doing.