V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 8718 views
    This topic created in 5245 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   ·   Solana   ·   2462 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 06:05 · PVG 14:05 · LAX 23:05 · JFK 02:05
    ♥ Do have faith in what you're doing.