基本上,我正在尝试从节点服务器检索刷新的消息,并且遇到了错误,我试图纠正该错误,以便我可以进一步开发Web应用程序。
我尝试修改代码,甚至在nunjucks文档的帮助下,我还修复了nunjucks格式的所有问题。经过检查,似乎我无法从nunjucks if表达式中运行“ typeof”。
{% if (typeof messages.error != "undefined") %}
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Oops!</strong> {{ messages.error }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<script>console.log("first");</script>
{% endif %}
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/', function(req, res, next) {
const url = req.body.url;
if (!url.startsWith('https://') && !url.startsWith('http://')) {
req.flash('error', 'That doesn\'t appear to be a valid URL to me.');
}
return;
});
我正试图使警报不出现,而不是整个应用程序因错误而崩溃。
Template render error: (e:\Programming\nodejs\invisi.link\views\index.html) [Line 33, Column 23]
parseAggregate: expected comma after expression
at Object._prettifyError (e:\Programming\nodejs\invisi.link\node_modules\nunjucks\src\lib.js:36:11)
at Template.render (e:\Programming\nodejs\invisi.link\node_modules\nunjucks\src\environment.js:542:21)
at e:\Programming\nodejs\invisi.link\node_modules\nunjucks\src\environment.js:366:27
at createTemplate (e:\Programming\nodejs\invisi.link\node_modules\nunjucks\src\environment.js:315:9)
at handle (e:\Programming\nodejs\invisi.link\node_modules\nunjucks\src\environment.js:327:11)
at e:\Programming\nodejs\invisi.link\node_modules\nunjucks\src\environment.js:339:9
at next (e:\Programming\nodejs\invisi.link\node_modules\nunjucks\src\lib.js:280:7)
at Object.asyncIter (e:\Programming\nodejs\invisi.link\node_modules\nunjucks\src\lib.js:286:3)
at Environment.getTemplate (e:\Programming\nodejs\invisi.link\node_modules\nunjucks\src\environment.js:321:9)
at Environment.render (e:\Programming\nodejs\invisi.link\node_modules\nunjucks\src\environment.js:360:10)
at NunjucksView.render (e:\Programming\nodejs\invisi.link\node_modules\nunjucks\src\express-app.js:22:9)
at tryRender (e:\Programming\nodejs\invisi.link\node_modules\express\lib\application.js:640:10)
at Function.render (e:\Programming\nodejs\invisi.link\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (e:\Programming\nodejs\invisi.link\node_modules\express\lib\response.js:1012:7)
at e:\Programming\nodejs\invisi.link\index.js:26:9
at Layer.handle [as handle_request] (e:\Programming\nodejs\invisi.link\node_modules\express\lib\router\layer.js:95:5)
at next (e:\Programming\nodejs\invisi.link\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (e:\Programming\nodejs\invisi.link\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (e:\Programming\nodejs\invisi.link\node_modules\express\lib\router\layer.js:95:5)
at e:\Programming\nodejs\invisi.link\node_modules\express\lib\router\index.js:281:22
at Function.process_params (e:\Programming\nodejs\invisi.link\node_modules\express\lib\router\index.js:335:12)
at next (e:\Programming\nodejs\invisi.link\node_modules\express\lib\router\index.js:275:10)```