[英]How do I change the text color of a default UserCreationForm in Django?
我正在使用 django 和引導程序開發一個簡單的網站。 我使用 UserCreationForm class 制作了一個標准注冊頁面。 但我想讓文本更暗一點,這樣它更清晰,並且與背景圖像和遮罩形成良好的對比。 什么是最好的解決方案?
查看模塊
def register(request):
#if the request method is a 'get'
#Yes initial data
if request.method != 'POST':
form = UserCreationForm()
#no initial data
#f the request method is a 'post'
else:
form = UserCreationForm(data=request.POST)
if form.is_valid():
new_user=form.save()
authenticated_user = authenticate(username=new_user.username,
password=request.POST['password1'])
login(request, aunthenticated_user)
return HttpResponseRedirect(reverse('my_websites:home'))
context = {'form': form}
return render(request, 'users/register.html', context)
自舉
{% extends "pages/base.html" %}
{% load bootstrap5 %}
{% block header %}
<div="container my-5">
<div class="bg-image position-relative rounded" style="background:url('https://wallpaperaccess.com/full/1708426.jpg') no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; height: 100vh;">
<div class="mask position-absolute rounded p-4 top-0 end-0 bottom-0 start-0" style="background-color: rgba(251, 251, 251, 0.8);">
<h2 class="text-center display-6"> Register </h2>
<form method="post" action="{% url 'users:register' %}" class="form text-dark" style="max-width: 400px; margin:0 auto;">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button name="submit" class="btn btn-dark">Register
</button>
{% endbuttons %}
<input type="hidden" name="next" value="{% url 'my_websites:home' %}" />
</form>
</div>
</div>
</div>
感謝您的時間。
看起來您正在使用 Bootstrap,它預定義了一組 CSS 類,您可以將其用於 colors。
嘗試將您的<h2 class="text-center display-6"> Register </h2>
標簽更改為<h2 class="text-center display-6 text-danger"> Register </h2>
- 它可能會變成紅色.
bootstrap_form
標簽允許你傳遞參數來控制應用的 CSS class 屬性。
例如,嘗試:
{% bootstrap_form form field_class="text-danger" %}
對於可以傳遞的可用參數,請參閱文檔: https://django-bootstrap-v5.readthedocs.io/en/latest/templatetags.html#bootstrap-field
有關如何將 colors 與 Bootstrap 一起使用的更多信息,包括定義要使用的自己的顏色主題,請參見此處: https://getbootstrap.com/docs/5.0/utilities/colors/祝你好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.