My framework is raising a syntax error when I try to execute this code:
from django.template import Template, TemplateSyntaxError
try:
Template(value)
except TemplateSyntaxError as error:
raise forms.ValidationError(error)
return value
And here's the error:
from template_field import TemplateTextField, TemplateCharField
File "C:\django\internal\..\internal\cmsplugins\form_designer\template_field.py", line 14
except TemplateSyntaxError as error:
^
SyntaxError: invalid syntax
What's going on?
Python code can make calls directly into C modules. Those C modules can be either generic C libraries or libraries built specifically to work with Python. Cython generates the second kind of module: C libraries that talk to Python's internals, and that can be bundled with existing Python code.
The alternate syntax except SomeException as err
is new in 2.6. You should use except SomeException, err
in 2.5.
You can't have an empty try
block like that in Python. If you just want to do nothing in the block (for prototyping code, say), use the pass
keyword:
from django.template import Template, TemplateSyntaxError
try:
pass
except TemplateSyntaxError as error:
Template(value)
raise forms.ValidationError(error)
return value
Edit: This answers the original version of the question. I'll leave it up for posterity, but the question has now been edited, and @jleedev has the correct answer to the revised question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With