在视图中:
return render_to_response('template.html',
{'headers': list(sort_headers.headers()) },
context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
在模板中:
{{ headers }}
<br />
{{ headers|slice:"1" }}
Run Code Online (Sandbox Code Playgroud)
在浏览器中:
[{'url': '?ot=desc&o=0', 'text': 'Nombre', 'class_attr': ' class="sorted ascending"', 'sortable': True}, {'url': '?ot=asc&o=1', 'text': 'Valor', 'class_attr': '', 'sortable': True}, {'url': '?ot=asc&o=2', 'text': 'Inventario', 'class_attr': '', 'sortable': False}, {'url': '?ot=asc&o=3', 'text': 'Fecha Creacion', 'class_attr': '', 'sortable': True}]
[{'url': '?ot=desc&o=0', 'text': 'Nombre', 'class_attr': ' class="sorted ascending"', 'sortable': True}]
Run Code Online (Sandbox Code Playgroud)
我得到一个列表节点{{ headers|slice:"1" }},但现在,如何获得一个dict值?例如'url'返回'?ot=desc&o=0'.
注意:不能使用{% for %}.
我想Django的网址只有2的替代品/module/in/或/module/out/
我正在使用
url(r'^(?P<status>\w+[in|out])/$',
'by_status',
name='module_by-status'),
Run Code Online (Sandbox Code Playgroud)
但是,它匹配其他模式,如/module/i/,/module/n/和/module/ou/.
任何提示都很赞赏:)
我需要javascript/jquery专家帮助解决下一个问题:
---- 1. 此javascript警告select html标记中所选选项的ID:
$(function(){
$("#id_productos_list").change(
function(){
var op = $(this).selectedValues()
alert(op);
}
);
});
Run Code Online (Sandbox Code Playgroud)
---- 2.这个javascript克隆html代码:
function cloneMore(selector, type) {
var newElement = $(selector).clone();
var total = $('#id_' + type + '-TOTAL_FORMS').val();
newElement.find(':input').each(function() {
var name = $(this).attr('name').replace('-' + (total-1) + '-','-' + total + '-');
var id = 'id_' + name;
$(this).attr({'name': name, 'id': id}).val('').removeAttr('checked');
});
newElement.find('label').each(function() {
var newFor = $(this).attr('for').replace('-' + (total-1) + '-','-' + total + '-');
$(this).attr('for', newFor);
});
total++; …Run Code Online (Sandbox Code Playgroud) 我正在编写一个应用程序,它将根据首次访问者显示注册视图.
什么以及如何使用Django更好的方法?
thxs.
我有一个问题,读取一个txt文件插入mysql数据库表,te sniped这段代码:
文件包含第一行:" aclaración "
archivo = open('file.txt',"r")
表示archivo.readlines()中的行:
.... body = body + line
model = MyModel(body = body)
model.save()
我得到一个DjangoUnicodeDecodeError:
'utf8'编解码器无法解码位置8中的字节:无效数据.你传入'aclaraci\xf3n'(类型'str')Unicode错误提示
无法编码/解码的字符串是:araci n.
我尝试了body.decode('utf-8'),body.decode('latin-1'),body.decode('iso-8859-1'),没有解决方案.
你能帮我吗?任何提示都是apreciated :)
我的语言环境dateformat是dd/mm/yyyy,Django正在申请AAAA-MM-DD
当用户输入时04/11/2009 Django提出:
_('Enter a valid date in YYYY-MM-DD format.'))
Run Code Online (Sandbox Code Playgroud)
我使用简单的html输入字段type ="text",而不是forms.DateField
谢谢 :)