【问题标题】:Cannot GET /ejs file无法获取 /ejs 文件
【发布时间】:2020-11-02 03:56:53
【问题描述】:

我正在尝试使用 html 完成调查页面的统计信息 当我尝试连接到网页的 ejs 视图时,它给了我无法 GET /showResults

// Entry point for the application

// express application
var express = require('express');
// require the controller we make
var surveyController = require('./surveyController');

var app = express();

// set up template engine
app.set('view engine', 'ejs');

// static file serving
app.use(express.static('./public'));

// fire function from surveyController
surveyController(app);

// listen to port
app.listen(8080);
console.log('listening port 8080');

我有一个网页和 app.js 文件的 HTML 视图,似乎在控制台上运行,但是当我登录 http://localhost:8080/showResults 时出现错误

【问题讨论】:

    标签: html node.js


    【解决方案1】:

    您可以在此处使用ejs,通过app.js 中的以下设置查看

    // view engine setup
    
    app.set('views', path.join(__dirname, 'views'));
    app.set('view engine', 'ejs');
    
    // use res.render to load up an ejs view file
    
    app.get('/', function(req, res) {
        res.render('<folder>/index');
    });
    

    【讨论】:

      猜你喜欢
      • 2018-01-24
      • 2022-01-07
      • 2019-01-21
      • 1970-01-01
      • 2022-11-14
      • 2020-10-06
      • 2016-10-10
      • 2020-07-20
      • 2017-09-11
      相关资源
      最近更新 更多