This topic created in 4405 days ago, the information mentioned may be changed or developed.
最近在学习Django,自己在看官方文档写个forum程序
对CharField中的max_length很不解
Django中的max_length似乎是指字符的个数?
比如我设定max_length=4,那我在admin后台中最多可以输入4个英文字符
也可以输入4个中文字符
别外Django模板中的truncatechars过滤器也是这样
像{{ value|truncatechars:9 }}就会限制在9个英文字符,中文也是9个
问题是:
我希望设定的是最大的字节(?)不是字符的个数
例如最大可以是4个中文或8个英文字符这种
不知道问题出在哪里?应该如何着手?
谢谢。
3 replies 1970-01-01 08:00:00 +08:00  | | 1 RIcter Apr 6, 2014 1 Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> a=u'啊' >>> len(a) 1 >>> a='啊' >>> len(a) 2 >>>
不谢= =! |
 | | 2 mengzhuo Apr 6, 2014 max_length转换成MYSQL是varchar,这个是按字符数计算的,你希望的效果只能自己写filter了 |