本文介绍了如何在django url中有unicode字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Url conf如下

My Url conf is as follows

url(ur'^phrase/(?P<lang>[_A-Za-z]+)/(?P<phrase>[%A-Za-z0-9]+)/$', 'gs.langdb.views.phrases'),

Views.phrases返回JSON对象

Views.phrases returns JSON object

def phrases(request,lang,phrase):                                                               
langs = Langauges.objects.all().values(
    'language',
    'lang_code')
lang_list = []
try:                                              
    map(lambda x: lang_list.append(x),langs)
    json = simplejson.dumps(lang_list)
    return HttpResponse(json, mimetype='application/json')
except TypeError:
    print "Can't convert language to Json \n"

我的观点如下: -

My View is as follows:-

$("#phrase").autocomplete({
    source: function(request,response){
        var selectedValue = document.getElementById("language").value;
        $.ajax({
             url: "/phrase/"+selectedValue+"/"+request.term,
             dataType : 'json',
             type : 'GET',
             data : {},
             success : function(data,selectedValue) {

             }
       });
    },
});

<div class="ui-words">
       <label for="phrase">Input word: </label>
       <input id="phrase">
</div>

我用于测试的字符串,अनिश

String which i used for testing, अनिश

我在服务器日志中出现的错误

Error which i have got in the server log

GET / phrase / Mr_in /%E0%A4%85%E0%A4%A8%E0%A4% BF%E0%A4%B6 HTTP / 1.1404 2275

"GET /phrase/Mr_in/%E0%A4%85%E0%A4%A8%E0%A4%BF%E0%A4%B6 HTTP/1.1" 404 2275

我不知道我是否需要指定编码?
这个问题的任何帮助将被贴上来。

I am not sure whether where i need to specify encodings?Any help in this issue will be appriciated

推荐答案

尝试这个url模式:

url(r'^phrase/(?P<lang>[_A-Za-z]+)/(?P<phrase>([^/]+))/$', 'gs.langdb.views.phrases'),

这篇关于如何在django url中有unicode字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 21:27