Mohammed Jaseem Tp
Mohammed Jaseem Tp

Reputation: 118

name 'message' is not defined in django python

@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

Upvotes: 0

Views: 1765

Answers (2)

Manoj Tolagekar
Manoj Tolagekar

Reputation: 1970

you misspelled there:

first import it:

from django.contrib import messages

then:

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

Upvotes: 0

Mohammed Jaseem Tp
Mohammed Jaseem Tp

Reputation: 118

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

and imported "from django.contrib import messages"

Then it works fine

Upvotes: 2

Related Questions