Django/Dajaxice 和国际字符的问题
我在使用具有国际字符的 Djajaxice 时遇到问题...
我有一个 django 模板...在该模板中是以下选择:
<select name="region" id="id" onchange="Dajaxice.crc.regions('my_callback',{'data':this.value});">
<option value="" selected="selected" ></option>
{% for region in regions %}
<option value="{{ region.region }}">{{ region.region }}</option>
{% endfor %}
</select>
正如您在选择的 onchange 上看到的,我正在调用区域函数并向其传递两个参数。回调的名称和选定的值
这是 ajax.py 文件中的函数
def regions(request, data):
CityList = City.objects.filter(region__exact=data)
out = "".join(['<option value="%s">%s</option>' % (c.city,c.city) for c in CityList])
return simplejson.dumps(out)
dajaxice_functions.register(regions)
这工作正常,并且使用相关数据调用模板中的 JavaScript 函数,当区域名称没有任何名称时,不会出现任何问题里面有国际人物。
例如说“安塔利亚”。然而,当像“穆拉”这样的地区出现时,它就不起作用了。经过仔细检查,变量数据包含“Mu%u011Fla”,我似乎无法将其恢复为我认为必要的格式,以便 Django 可以正确访问模型数据。
我在页面顶部使用了魔术引号,我尝试使用 data.decode('string-escape') 对其进行转义,并将其推到 utf-8 和后面之间。但我尝试的任何方法似乎都不起作用。这
是 Dajaxice、Django 或 python 问题...还是我在这里遗漏了一些非常简单的东西?
我已经花了两天时间,试图解决这个问题......提前非常感谢您能够提供的任何帮助。
干杯
I am having a problem using Djajaxice with international characters...
I have a django template...in that template is the following select:
<select name="region" id="id" onchange="Dajaxice.crc.regions('my_callback',{'data':this.value});">
<option value="" selected="selected" ></option>
{% for region in regions %}
<option value="{{ region.region }}">{{ region.region }}</option>
{% endfor %}
</select>
As you can see on the onchange of the select I am calling the regions function and passing it two parameters. The name of the call back and the selected value
Here is the function in the ajax.py file
def regions(request, data):
CityList = City.objects.filter(region__exact=data)
out = "".join(['<option value="%s">%s</option>' % (c.city,c.city) for c in CityList])
return simplejson.dumps(out)
dajaxice_functions.register(regions)
This works ok and calls, with the relevant data, my JavaScript function in the template with no problems when the name of the region does not have any international characters in it.
Say 'Antalya' for example. However when a region such as 'Muğla' comes along, it doesn't work. On close inspection the variable data contains 'Mu%u011Fla' and I can't seem to get it back to what I assume is the necessary format so that Django can access the model data correctly.
I have used the magic quotes at the top of the page, I have tried using unescaping it with data.decode('string-escape') and shoving it between utf-8 and back..but nothing I try seems to work...
Is this a Dajaxice, Django or python issue...or am I missing something really simple here?
I have been at it two days now, trying to figure this out....so many thanks in advance for any help you may be able to provide.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,修复了这个问题...
因此,对于使用 Dajaxice 并使用国际字符的其他人,您应该更改 Dajaxice.core.js 文件中的第 10 行,如下所示:
send_data.push('argv='+escape(JSON.stringify( argv)));
对此:
send_data.push('argv='+encodeURIComponent(JSON.stringify(argv)));
一切都很好。
唷,两天零几个小时的生命就这样滑入了代码的浑水中……
帮助我们大家!
Ok, fixed this...
So for anyone else using Dajaxice, and using international characters you should change line 10 in the Dajaxice.core.js file from the following:
send_data.push('argv='+escape(JSON.stringify(argv)));
to this:
send_data.push('argv='+encodeURIComponent(JSON.stringify(argv)));
and all works well.
Phew two days and a few hours of life slipped into the murky waters of code.... ...
help us all!