推荐学习书目
› 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 · 9303 views
    This topic created in 5449 days ago, the information mentioned may be changed or developed.
    6 replies  •  1970-01-01 08:00:00 +08:00
    vicalloy
    vicalloy
    Dec 20, 2011
    1
    用普通的charfield,没必要一定用slug
    ywjno
    ywjno
    Dec 20, 2011
    2
    用encode的方式,
    不光是中文,各种不在asc码上的文字都能搞定了
    yanng
    yanng
    OP
    Dec 20, 2011
    3
    @reus 谢谢,我去看看
    yanng
    yanng
    OP
    Dec 20, 2011
    4
    @ywjno encode decode和不这样做直接显示汉字,在SEO或者其他方面有没有什么区别?
    lueo
    lueo
    Jul 17, 2012❤️1
    6
    这个实现非常完整,也很稳定,针对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   ·   1345 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 17:19 · PVG 01:19 · LAX 09:19 · JFK 12:19
    ♥ Do have faith in what you're doing.