It's a question from django form!

Asked 2 years ago, Updated 2 years ago, 41 views

The membership page was made as follows.

{% extends "base.html" %}
{% {% block title %}User Registration{% endblock %}
{% {% block head %}User Registration{% endblock %}
{% {% block content %}
    <form method="post" action=".">{% csrf_token %}
        <table border="0">
            {{ {{ form.as_table }}
        </table>
        <input type="submit" value="Sign Up" />
    </form>
    <br>
    <a href="/login">Sign In</a>
{% {% endblock %}

Here, {{form.as_table}}} represents the membership part, but I don't know how to access and decorate it with CSS. For example, I want to increase the length and put a placeholder in the box and bring all the parts in the middle, what should I do? And how do I erase this part of the username next to it? Masters, please answer.

Thank you.

python django

2022-09-21 19:52

3 Answers

<style>
th{
        text-align: left;       
    }
td{
        text-align: right;      
    }   
</style>

There are many ways to add css, but you can also add it like this. If you want to apply it only to that table, you can give the class to the table.

Placeholder can be defined like this in the form.

name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Name'}))


2022-09-21 19:52

See this link .

Example:

from django import forms

class AuthenticationForm(forms.Form):
    username = forms.CharField(
        max_length=254,
        widget=forms.TextInput(attrs={'class': "input-lg"}),
    )
    password = forms.CharField(widget=forms.PasswordInput)

If you look at the username form field above, you can set widget as Text Input, and there is a way to give a class (CSS) to an attribute.

Apply the desired CSS to all of the above form fields.

And usernmae: is the label specified in the form field, so I think you can give it to label=''.

Example:

from django import forms

class AuthenticationForm(forms.Form):
    username = forms.CharField(
        max_length=254,
        widget=forms.TextInput(attrs={'class': "input-lg"},label=''),
    )
    password = forms.CharField(widget=forms.PasswordInput)


2022-09-21 19:52

Thank you both for your answers!


2022-09-21 19:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.