我正在尝试使用 CSS 设计表单样式。首先,除了官方文档之外,我还没有看到完整的示例,因此我将不胜感激任何博客条目或文章。
现在在我的表单上,典型的 Charfield 被翻译成 html,如下所示:
<input type="text" name="artists" id="id_artists" />
如果我的表单在某些字段上包含错误,则前面的 Charfield 会记住该值并执行:
<input type="text" name="artists" value="Pink Floyd" id="id_artists" />
如何在 django 表单中获取此值 (value="Pink Floyd"
)?假设我的字段是 {{form.artists}}
,我可以使用 {{form.artists}}
作为字段, {{form.artists.label }}
作为标签,{{form.artists.errors}}
和 {{form.artists.help_text}}
,但是这个值怎么样?
提前致谢!
最佳答案
专门创建输入字段,而不是依赖 django 自动创建它。
类似于:
<input type="text" name="artists" id="id_artists" value="{{form.artists.title}}" />
应该可以
关于django - 表单样式和 django 表单值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/625831/