【发布时间】:2014-04-18 23:48:18
【问题描述】:
我有模特
# models.py
from django.db import models
class Foo(models.Model):
# ...
color = models.CharField(max_length=7, null=True)
color 应该存储一个十六进制颜色。而不是input type="text",我想使用html5 input type "color"。
我通过设置以下表单对象进行了尝试:
# forms.py
from django.forms import ModelForm, CharField
class FooForm(ModelForm):
class Meta:
model = Foo
widgets = {
'color': CharField(attrs={'type': 'color'}),
}
但是,这给了我以下错误消息
init() 得到了一个意外的关键字参数“attrs”
我做错了什么,我该如何做对?
【问题讨论】:
-
attrs不是字段的参数,而是小部件的参数。 -
好的,但他们不是在这里这样做吗:docs.djangoproject.com/en/1.6/topics/forms/modelforms/…?还是我混淆了什么?
标签: python django html django-models