ブートストラップによるDjangoメッセージ設定

4179 ワード

設定パイ
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',}

ビューパイ
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})
HTMLで実行する必要はありませんでした