gpt4 book ai didi

html - Django 中模板标签的样式

转载 作者:行者123 更新时间:2023-11-28 07:56:26 26 4
gpt4 key购买 nike

我正在尝试设置我的注册表单的样式,但由于它使用模板标签合并要填写的字段,我不确定该怎么做。

我希望我的注册表格看起来像我的登录表格。登录表单的代码在这里:

{% extends 'rango/base.html' %}

{% load staticfiles %}

{% block body_block %}

<link href="http://getbootstrap.com/examples/signin/signin.css" rel="stylesheet">

<form class="form-signin" role="form" method="post" action=".">
{% csrf_token %}

<h2 class="form-signin-heading">Please sign in</h2>

<input class="form-control" placeholder="Username" id="id_username" maxlength="254" name="username" type="text" required autofocus=""/>
<input type="password" class="form-control" placeholder="Password" id="id_password" name="password" type="password" required />

<button class="btn btn-lg btn-primary btn-block" type="submit" value="Submit" />Sign in</button>
</form>

{% endblock %}

...我的注册表单代码如下所示:

{% extends 'rango/base.html' %}

{% block title %}Register{% endblock %}

{% block body_block %}

<link href="http://getbootstrap.com/examples/signin/signin.css" rel="stylesheet">

<div class="container">
{% if registered %}
<p>Thank you for registering.</p>

<p><a href="/rango/login/">Login</a> when you are ready to rango.</p>
{% else %}
<form class="form-signin span8" id="user_form" method="post" action="/rango/register/"
enctype="multipart/form-data">
{% csrf_token %}
<h2 class="form-signin-heading">Sign up here</h2>
<!-- Display each form here -->

{% for field in user_form.visible_fields %}
{{ field.errors }}
{{ field.help_text }}<br />
{{ field }}<br/>
{% endfor %}

{% for field in profile_form.visible_fields %}
{{ field.errors }}
{{ field.help_text }}<br />
{{ field }}<br />
{% endfor %}


<br />
<!-- Provide a button to click to submit the form. -->
<button class="btn btn-primary" type="submit" name="submit">Register</button>
</form>
{% endif %}
</div>
</div>
{% endblock %}

所以问题是“当注册表单使用模板标签显示字段时,我该如何设置它的样式?

最佳答案

定义表单类时,可以这样添加 css 属性:

username_field = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}))

关于html - Django 中模板标签的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30090613/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com