Openwrt luci 用模板做页面报错: unfinished string near '"'

摘要: 记录在用模板方式开发luci的时候,一个一不小心的产生的报错:unfinished string near '"',这个问题最大的可能就是windows下编辑的文件,直接上传到linux下用产生的。

Openwrt的luci页面开发过程中,会自己定义模板页面,然后再渲染出来,返回到浏览器。我在按照官网的一个例子自定义页面的过程中。菜单的展示,CBI 方式都没有问题,但用模板方式就出问题了。报错如下:

/usr/lib/lua/luci/template.lua:81: Failed to load template 'customize/view_constants'.
Error while parsing template '/usr/lib/lua/luci/view/customize/view_constants.htm':
Syntax error in /usr/lib/lua/luci/view/customize/view_constants.htm:1: unfinished string near '"'
stack traceback:
	[C]: in function 'error'
	/usr/lib/lua/luci/template.lua:81: in function '__init__'
	/usr/lib/lua/luci/util.lua:65: in function 'Template'
	/usr/lib/lua/luci/template.lua:28: in function 'render'
	/usr/lib/lua/luci/dispatcher.lua:1020: in function 'dispatch'
	/usr/lib/lua/luci/dispatcher.lua:478: in function </usr/lib/lua/luci/dispatcher.lua:477>

看样子就是字符串解析问题。

分析问题,逐步定位, 我定义的页面如下,非常简单:

<%+header%>
    <h2>My LUCI Template Test Page</h2>
<%+footer%>

尽管这么简单,还是会报错,根据错误提示,基本分析是字符串解析出的问题。首先想到的是,不换行吧,直接把模板改成这样:

<%+header%>    <h2>My LUCI Template Test Page</h2>   <%+footer%>

也就是不换行,结果正常了。界面显示如下:


但这真正解决问题了吗,在做页面的过程中,模板页面不可能不换行的。所以又回到原来多行的方式。因为我是在idea 里面编辑的模板,然后ssh上传到openwrt的luci 对应文件夹中去的。在openwrt中直接vi 命令打开看看多行情况下是什么样子.

到此为止,我想大家都知道原因了。编辑器惹的祸,或者是window与linux下回车键编码不一致造成的。所以需要转换一下,这种转换很多文本编辑器都有这个功能,这里就不记录了。但在idea里面可以直接在编辑器的状态栏修改.

修改之后,所有的回车就会用 linux下的编码,然后一切正常了。

上一篇: Centos 7 下安装 Lua 报错 lua.c:80:31: fatal error: readline/readline.h: No such file
下一篇: 在微软必应网站上获取高清网页背景图
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号