V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2011 年 12 月 20 日 · 8535 次点击
    这是一个创建于 5144 天前的主题,其中的信息可能已经有所发展或是发生改变。
    6 条回复    1970-01-01 08:00:00 +08:00
    vicalloy
        1
    vicalloy  
       2011 年 12 月 20 日
    用普通的charfield,没必要一定用slug
    ywjno
        2
    ywjno  
       2011 年 12 月 20 日
    用encode的方式,
    不光是中文,各种不在asc码上的文字都能搞定了
    yanng
        3
    yanng  
    OP
       2011 年 12 月 20 日
    @reus 谢谢,我去看看
    yanng
        4
    yanng  
    OP
       2011 年 12 月 20 日
    @ywjno encode decode和不这样做直接显示汉字,在SEO或者其他方面有没有什么区别?
    lueo
        6
    lueo  
       2012 年 7 月 17 日   ❤️ 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
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1392 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 17:07 · PVG 01:07 · LAX 09:07 · JFK 12:07
    ♥ Do have faith in what you're doing.