[Answered ]-Bootstrap button doesn't display properly in django form

1👍

The correct class for Bootstrap buttons is btn btn-primary for a primary button. There is no btn-default.

To avoid the "This field is required labels", do the classic Post/Redirect/Get. So,

def register(request):

    form = CustomUserCreationForm(request.POST or None)

    if form.is_valid():
        user = form.save()
        login(request, user)
        return redirect('dwitter:dashboard')

    return render(request, "users/register.html", {"form": form})

The idea being that if the request is a POST, then request.POST will have data, thus it will be True, and you can check for form validity. If the request is a GET, then request.POST will not have data, thus it will be False, so the None part will take over, giving you an unbound, empty form. The last return will thus have an empty, unbound form, so it will not have any errors. If the form is valid, the the redirect will take place.

Leave a comment