使用 Parse.com Express.js 将 .ejs 扩展名更改为 .html [英] Change .ejs extension to .html using Parse.com Express.js

查看:22
本文介绍了使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆