亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 7711 | 回復(fù): 4
打印 上一主題 下一主題

django 中使用中文查詢有問題? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2008-02-27 11:07 |只看該作者 |倒序瀏覽
最近碰到一個問題,一直沒有解決,希望這里的朋友能幫忙想想辦法,謝過了!

登錄 mysql 客戶端執(zhí)行以下語句查詢有數(shù)據(jù):
sql=select * from portal_Tresource where keywords like "%最新報道%" order by material_time desc


在 views.py 中通過 django 的 model 查詢卻沒有數(shù)據(jù),代碼如下:
result=Tresource.objects.all().filter(keywords__contains=u'最新報道').order_by('-material_time')


如果將 filter 中的條件改為非中文的字段,查詢結(jié)果正確,而且頁面顯示也是對的,能正確顯示查詢出來的中文。

以下是我機器上面開發(fā)環(huán)境的編碼:
mysql 數(shù)據(jù)庫:        characterset:    utf8
settings.py:          LANGUAGE_CODE = 'zh-cn'
                             DEFAULT_CHARSET = 'gb18030'
其它py文件和頁面均為 utf-8

[ 本帖最后由 honkily 于 2008-3-4 16:05 編輯 ]

論壇徽章:
0
2 [報告]
發(fā)表于 2008-02-29 15:00 |只看該作者

回復(fù) #1 honkily 的帖子

分別修改成

  1. result=Tresource.objects.all().filter(keywords__contains='最新報道').order_by('-material_time')
復(fù)制代碼

  1. result=Tresource.objects.all().filter(keywords__contains=u'最新報道'.encode("gb18030")).order_by('-material_time')
復(fù)制代碼

后測試的效果如何?

論壇徽章:
0
3 [報告]
發(fā)表于 2008-03-03 22:27 |只看該作者
不好意思,我這幾天在公司無法登錄論壇

明天試試看

論壇徽章:
0
4 [報告]
發(fā)表于 2008-03-04 16:14 |只看該作者
achaoge,
我將代碼修改為你說的樣子,直接報錯了:
DjangoUnicodeDecodeError at /model6/
'utf8' codec can't decode bytes in position 0-1: invalid data. You passed in '\xd7\xee\xd0\xc2\xb1\xa8\xb5\xc0' (<type 'str'>)
Request Method: GET
Request URL: http://localhost:8000/model6/
Exception Type: DjangoUnicodeDecodeError
Exception Value: 'utf8' codec can't decode bytes in position 0-1: invalid data. You passed in '\xd7\xee\xd0\xc2\xb1\xa8\xb5\xc0' (<type 'str'>)
Exception Location: c:\python24\Lib\site-packages\django\utils\encoding.py in force_unicode, line 60
Python Executable: c:\python24\python.exe
Python Version: 2.4.4
Python Path: ['F:\\mytest\\mytest', 'c:\\python24\\lib\\site-packages\\setuptools-0.6c3-py2.4.egg', 'c:\\python24\\lib\\site-packages\\pygments-0.8.1-py2.4.egg', 'C:\\WINDOWS\\system32\\python24.zip', 'F:\\mytest\\mytest', 'c:\\python24\\DLLs', 'c:\\python24\\lib', 'c:\\python24\\lib\\plat-win', 'c:\\python24\\lib\\lib-tk', 'c:\\python24', 'c:\\python24\\lib\\site-packages', 'c:\\python24\\lib\\site-packages\\PIL', 'c:\\python24\\lib\\site-packages\\kodos']

Unicode error hint
The string that could not be encoded/decoded was: ?1?7?1?7?1?7?1?7?1?7?1?7?1?7

...
zhangsf 該用戶已被刪除
5 [報告]
發(fā)表于 2008-04-19 21:08 |只看該作者
提示: 作者被禁止或刪除 內(nèi)容自動屏蔽
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP