Django Allauth-如何向字段添加自定义CSS类? [英] Django Allauth - How to add custom css class to fields?
问题描述
在login.html中,我有:
< form class = login method = POST action = {%url'account_login'%}>
{%csrf_token%}
{{form.as_p}}
如何在世界上向字段添加自定义CSS类和其他属性?互联网上似乎没有人以前有过此问题。我只需要添加一个简单的类即可。预先感谢有人回答。我真的希望这对其他人有帮助。
您正在使用Django通过调用<$ c为您创建的HTML $ c> form.as_p 就像这个例子一样。
您可能在寻找什么下面是该示例。您可以在模板中编写更多标记。 / p>
听起来您可能对此也有兴趣。创建表单并使用类似以下内容的方式指定要添加到字段中的类:
myfield = form.CharField(
widget = forms.TextInput(attrs = {'class':'myclass'}))
现在c模板中所有 form.myfield
都会创建一个输入文本字段,其上带有类 myclass
。
In login.html I have:
<form class="login" method="POST" action="{% url 'account_login' %}">
{% csrf_token %}
{{form.as_p}}
How in the world can I add custom css classes and other atributes to the fields? Nobody on the internet seems to have had this problem before. I just need to add something as simple as a class. Thanks in advance if someone answers this. I really hope this will be helpful for someone else.
You are using the HTML Django creates for you by calling form.as_p
just like this example.
What you might be looking for is the example right below it. Where you write more of the markup in the template.
It sounds like you might also be interested in this. Creating your form and specifying the classes to be added to the field using something like:
myfield = forms.CharField(
widget=forms.TextInput(attrs={'class':'myclass'}))
Now calling form.myfield
in the template will create an input text field with the class myclass
on it.
这篇关于Django Allauth-如何向字段添加自定义CSS类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!