Messages framework name error

26 views
Skip to first unread message

Zachary Sohovich

unread,
Dec 14, 2016, 12:13:12 PM12/14/16
to Django users
I'm attempting to add a success or error message to a form. As far as I can see, I've added everything correctly. But, when I try to submit the form with success or with error I get a 'NameError at /contact/' -> 'name message not defined'. Note that it says name message (not plural) not defined. Even though I only call messages. Here is my code 

# views.py

from django.shortcuts import render, redirect
from django.contrib import messages
from .models import Employee
from .forms import EmailForm
from django.core.mail import send_mail
from django.template import Context
from django.template.loader import get_template

# Create your views here.

def home(request):
   
return render(request, 'index.html')

def team(request):
    members
= Employee.objects.all()
   
return render(request, 'team.html', {'members':members})

def contact(request):
    form_class
= EmailForm
   
# forgive the unused code, will clean up later
   
if request.method == 'POST':
        form
= EmailForm(data=request.POST)
       
if form.is_valid():
            contact_name
= request.POST.get('contact_name', '')
            contact_email
= request.POST.get('contact_email', '')
            form_content
= request.POST.get('content', '')
           
template = get_template('contact_template.txt')
            context
= Context({'contact_name':contact_name,'contact_email':contact_email,'form_content':form_content,})
            content
= template.render(context)
            send_mail
('Website Email from ' + contact_name,content,contact_email, ['crowdc...@sneakycr0w.com'], fail_silently=False)
            messages
.success(request,'Email was successful!')
       
else:
            messages
.error = messages.error(request, 'Fix the error')
   
return render(request, 'contact.html', {'form': form_class, })


Antonis Christofides

unread,
Dec 14, 2016, 12:32:02 PM12/14/16
to django...@googlegroups.com

Hi,

could you show the full stack trace?

Antonis Christofides
http://djangodeployment.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5a2531f3-ff59-4061-9cf2-7645c678c8e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zachary Sohovich

unread,
Dec 14, 2016, 4:33:51 PM12/14/16
to Django users
So, I woke up this morning and went to go get the trace for you. Turned off my DEBUG setting in the settings.py and ran into some internal server errors. Fixed those, and then the messages error I was getting fixed itself, I guess. It's working now, randomly. Don't know what was causing it, guess it could've been my debug. 
Reply all
Reply to author
Forward
0 new messages