Wednesday, December 14, 2016

Re: Messages framework name error

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. 

On Wednesday, December 14, 2016 at 9:32:02 AM UTC-8, Antonis Christofides wrote:

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.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, })


--
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.

--
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+unsubscribe@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/960f5c59-95c0-43c4-97a0-0804612d0c32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment