Hi,
could you show the full stack trace?
Antonis Christofides
http://djangodeployment.com
On 12/14/2016 07:34 AM, Zachary Sohovich wrote:
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.pyfromdjango.shortcuts importrender,redirect fromdjango.contrib
importmessages from.models importEmployeefrom.forms
importEmailFormfromdjango.core.mail importsend_mail
fromdjango.templateimportContextfromdjango.template.loader importget_template
# Create your views
here.defhome(request):returnrender(request,'index.html')defteam(request):
members
=Employee.objects.all()returnrender(request,'team.html',{'members':members})defcontact(request):
form_class =EmailForm# forgive the unused code, will clean up
laterifrequest.method =='POST': form
=EmailForm(data=request.POST)ifform.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,['crowdcont...@sneakycr0w.com'],fail_silently=False)
messages.success(request,'Email was successful!')else:
messages.error =messages.error(request,'Fix the
error')returnrender(request,'contact.html',{'form':form_class,})
|
--
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+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@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
<https://groups.google.com/d/msgid/django-users/5a2531f3-ff59-4061-9cf2-7645c678c8e1%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/e154a043-c4a0-803a-6730-61f9cb6d4ab2%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.