DEV Community

Phansivang
Phansivang

Posted on

Django messages config with bootstrap

setting.py

from django.contrib.messages import constants as message_constants
MESSAGE_TAGS = {message_constants.DEBUG: 'debug',
                message_constants.INFO: 'info',
                message_constants.SUCCESS: 'success',
                message_constants.WARNING: 'warning',
                message_constants.ERROR: 'danger',}

Enter fullscreen mode Exit fullscreen mode

views.py

from django.contrib import messages
def Example(request):
    if request.method == 'POST':
        form = registerForm(request.POST)
        if form.is_valid():
            form.save()
           > messages.success(request,'Register successfully !')
           > messages.error(request,'Register successfully !')
           > messages.info(request,'Register successfully !')
           > messages.warning(request,'Register successfully !')
            return redirect('/login')
    else:
        form = registerForm()
    return render(request, 'app/register.html', {'form': form})
Enter fullscreen mode Exit fullscreen mode

JUST USE MY STEP AS I DID ABOVE NO NEED TO EXECUTE AT HTML

Top comments (0)