如何在Express中使用HTML作为视图引擎? [英] How do I use HTML as the view engine in Express?
本文介绍了如何在Express中使用HTML作为视图引擎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试从种子中简单的改变,并创建了相应的.html文件(例如index.html)。
I tried this simple change from the seed and created the corresponding .html files (e.g. index.html).
//app.set('view engine', 'jade');
app.set('view engine', 'html');
此文件保持不变:
exports.index = function(req, res){
res.render('index');
};
但运行时我得到
500错误:找不到模块'html'
500 Error: Cannot find module 'html'
我唯一选择使用'ejs'吗?我的意图是使用与AngularJS结合的纯HTML。
Is my only option to use 'ejs'? My intent was to use plain HTML in conjuction with AngularJS.
推荐答案
其他链接的答案可以正常工作, HTML,除非您想要设置时髦的路由,否则根本不需要使用视图引擎。相反,只需使用静态中间件:
The answers at the other link will work, but to serve out HTML, there is no need to use a view engine at all, unless you want to set up funky routing. Instead, just use the static middleware:
app.use(express.static(__dirname + '/public'));
这篇关于如何在Express中使用HTML作为视图引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文