Bri*_*n D 5 python django syntax
我尝试执行此代码时,我的框架引发了语法错误:
from django.template import Template, TemplateSyntaxError
try:
Template(value)
except TemplateSyntaxError as error:
raise forms.ValidationError(error)
return value
Run Code Online (Sandbox Code Playgroud)
这是错误:
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
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?
你不能try在Python中有这样的空块.如果你只想在块中做任何事情(比如说原型代码),请使用pass关键字:
from django.template import Template, TemplateSyntaxError
try:
pass
except TemplateSyntaxError as error:
Template(value)
raise forms.ValidationError(error)
return value
Run Code Online (Sandbox Code Playgroud)
编辑:这回答了问题的原始版本.我将把它留给子孙后代,但问题现在已被编辑,@ jleedev对修改后的问题有正确的答案.
| 归档时间: |
|
| 查看次数: |
398 次 |
| 最近记录: |