SJ19 SJ19 - 7 months ago 96
HTTP Question

Django/Python register page

I'm making a register page for my django (version 2.0) website, but it pretty messy to me, I'm pretty sure the bullet points and the additional information is not supposed to show up right away.

How can I make this register page look cleaner? Ie. just the username, password, and confirmation textbox, rather than all the messages.


enter image description here


<h2>Sign up</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Sign up</button>

Register view

def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')
user = authenticate(username=username, password=raw_password)
login(request, user)
return redirect('index')
form = UserCreationForm()
return render(request, 'todo/register.html', {'form': form})

Answer Source

There are many ways to achieve this.

  1. Overriding the default UserCreationForm()

    class MyForm(UserCreationForm): email = forms.EmailField(required=True) email.help_text = '' ...

  2. In the view template instead of using {{ form.as_p }} render the form manually

    <form action="" method="post">{% csrf_token %} {{ form.username.label }} {{ form.username }} ... </form>

  3. Design your custom template and map the field name to the form field name.

Hope it helps !

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download