Home > front end >  name 'message' is not defined in django python
name 'message' is not defined in django python

Time:09-19

@login_required(login_url='login_user') def hrmanager(request): template = 'Job_portal/job_listing.html'

if request.method == 'POST':
    form = job_posting_form(request.POST, request.FILES)
    if form.is_valid():
        form.save()
        message.success(request, 'Job Posted Successfully')
        return redirect('hrmanager')

job_posting = Job_posting_hr.objects.all()
user = "hrmanager"
job_add_form = job_posting_form()
context = {
    'edit_form': job_add_form,
    'user': user,
    'job_posting': job_posting
}

return render(request, template, context)

enter image description here

CodePudding user response:

It's not message, i changed it into "messages"

and imported "from django.contrib import messages"

Then it works fine

CodePudding user response:

you misspelled there:

first import it:

from django.contrib import messages

then:

messages.success(request, 'Job Posted Successfully')
  • Related