Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Error Messages in CRUD

How can I display Error messages in a Django CreateView

Jillian S. Estrella (she/her)
Jillian S. Estrella (she/her)
15,720 Points

Example using bootstrap:

from django.contrib import messages

class RegisterView(generic.CreateView):
    form_class = forms.UserCreateForm
    success_url = '/signin/'
    .
    .
    .
    def form_valid(self, form):
        form.save()
        messages.add_message(self.request, messages.SUCCESS, "User account created successfully!")
        return HttpResponseRedirect(self.success_url)