0

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.

Thanks!

enter image description here

Register.html

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

Register view

def register(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            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')
    else:
        form = UserCreationForm()
    return render(request, 'todo/register.html', {'form': form})
3
  • can you post the form validation and all the messages you have added in the place Commented Dec 21, 2017 at 12:04
  • Things would have been simpler if you had specified 1. the django version and 2. if that was the contrib.auth.forms.UserCreationForm or your own UserCreationForm... Commented Dec 21, 2017 at 12:07
  • Added the version (2.0) and it's the supplied contrib.auth.forms.UserCreationForm Commented Dec 21, 2017 at 12:47

2 Answers 2

2

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 !

Sign up to request clarification or add additional context in comments.

Comments

0

You did not specify where this UserCreationForm came from nor your django version, but anyway: searching django's code source it appears that those are the help_text for the various widgets / fields of the default contrib.auth.forms.UserCreationForm, so yes the "bullet points and the additional information" is actually "supposed to show up right away". And as far as I'm concerned (from a user perspective I mean) it's a good thing that it does "show up right away", so I don't have to retype username and passwords twice, thrice or more until I found out by trial/errors what the system expects (or, more often, just plain give up registering on this site).

Now if you really want to frustrate your users (and loose half of them on the way), you can of course mask all those useful informations by rendering the form manually so you have full control on which messages appear, when, where and how.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.