Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGerald Wells
12,763 Pointsinvalid syntax Django
when I saved my view.py it threw an error of "invalid syntax" I'm not seeing an issue.
messages.add_message(request, message.SUCCESS, "Message sent!")
Gavin Ralston
28,770 PointsWhen you say "it threw an error" was there a more specific message? Or did python simply say "invalid syntax" and crash?
The stack trace would come in handy here, if you could post it.
3 Answers
Gavin Ralston
28,770 Pointsdef contact_form(request):
form = forms.ContactForm()
if request.method == 'POST':
form = form.ContactForm(request.POST)
The second asignment is assigning form.ContactForm() instead of forms.ContactForm()
So I'm guessing the syntax error is there because there is no new_message method on that item.
Gerald Wells
12,763 PointsIt simply said "invalid syntax" crashed it said the invalid syntax can from line 30 the '^' was at the 'e' of messages.
Gerald Wells
12,763 Pointsmessages.add_message(request, messages.SUCCESS, "Message sent!")
^
SyntaxError: invalid syntax
Gerald Wells
12,763 PointsIt was there and a closing ) after ['name']
Gerald Wells
12,763 PointsGerald Wells
12,763 Pointswhole view: