本文介绍了使用Parse.com Express.js将.ejs扩展名更改为.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Parse.com的Express.js时,如何在视图文件中使用.html扩展名而不是.ejs?

How would I go about using .html extensions on my view files instead of .ejs when using Parse.com's Express.js?

我将EJS分隔符更改为<??>,因为我已经习惯了PHP.效果很好,但是我似乎无法更改视图文件的文件扩展名:

I changed the EJS delimiters to <? and ?> because I'm used to them from PHP. That worked fine, but I can't seem to change the file extension for my view files:

我尝试了以下操作:

var express = require('express');
var ejs = require('ejs');
var app = express();

ejs.open = '<?';
ejs.close = '?>';

app.set('view engine', 'ejs');
app.engine('.html', ejs.renderFile);
app.set('views', 'cloud/views'); app.use(express.bodyParser());

app.get('/', function(req, res) {
    res.render('Test', { message: 'Hello Express!' });
});

app.listen();

我收到一个内部服务器错误.

And I get an internal server error.

我还尝试过以相同的结果消除该行:

I've also tried eliminating this line with the same result:

app.set('view engine', 'ejs');

推荐答案

app.set('view engine', 'html');
app.engine('html', ejs.renderFile);

所以我将app.set设置为html,将app.engine设置为html,它对我有用.

So I did app.set to html and app.engine to html and it was working for me.

这篇关于使用Parse.com Express.js将.ejs扩展名更改为.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 20:21