简体   繁体   English

如何将样式与Django形式分离?

[英]how to decouple style from django form?

Our front designer (who has very weak programming experience) has trouble using attrs and so on in python code to control how form should look. 我们的前端设计师(编程经验非常弱的人)在python代码中无法使用attrs等来控制表单的外观。

Is there a recommended way of separating these concerns? 是否有建议的方法可以分离这些问题?

I've come across a django-crispy-forms but not sure if this is the right tool to achieve the goal. 我遇到过django-crispy-forms,但不确定这是否是实现目标的正确工具。

Your front end guy really shouldn't be modifying python code. 您的前端人员确实不应该修改python代码。 Use crispy-forms by all means to provide him with css ids/classes that he needs for specific form elements. 务必使用酥脆形式为他提供特定形式元素所需的css id /类。 It should still be you working with crispy-forms however, as it is not "easier" than modifying field attrs to add a class/id, just more comprehensive and powerful. 但是,仍然应该使用酥脆形式,因为它不比修改字段attrs来添加类/ id更“容易”,只是更加全面和强大。

You're not using style="" in attrs to write inline CSS right? 您不是在attrs使用style=""来编写内联CSS,对吗?

Edit: To answer your comment, it really depends what the work the front end guy is doing involves. 编辑:要回答您的评论,这实际上取决于前端人员正在进行的工作。 Is he writing very specific rules for one element at a time? 他是否一次为一个要素编写了非常具体的规则? For example "This text input is going to behave differently to every other text input on our site..." or does he just want to modify the css of all password inputs, or all select boxes etc? 例如“此文本输入的行为将与我们网站上的其他所有文本输入不同……”,还是他只是想修改所有密码输入或所有选择框等的CSS? If it's the latter, he shouldn't have to be going around adding attrs={"class": "select-box"} to every select box widget on every form. 如果是后者,则不必在每个表单的每个选择框小部件上添加attrs={"class": "select-box"} IMO it becomes the job of the django dev to make sure that the right class is present for every form field (crispy-forms is good for doing this). IMO成为django开发人员的工作,以确保每个表单字段都存在正确的类(脆皮表单很适合这样做)。

If his work would involve hassling you every 5 minutes asking for a class to be added to field_x and field_y then yes maybe it's best for him to be doing it himself. 如果他的工作涉及每5分钟向您讨价还价,要求将一门课添加到field_x和field_y,那么是的,也许对他来说最好是自己做。 But in terms of adding id's to specific fields there really is nothing simpler than the standard attrs usage. 但是就将id添加到特定字段而言,没有什么比标准attrs用法更简单的了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM