Question: Express app with EJS template giving Error: Failed to lookup view "/id" in views directory "/home/USER/Desktop/scholarship-app/views"

Question

Express app with EJS template giving Error: Failed to lookup view "/id" in views directory "/home/USER/Desktop/scholarship-app/views"

Answers 1
Added at 2017-01-05 09:01
Tags
Question

I am trying to render the request url for id in my express app and getting the following error

Error: Failed to lookup view "/id" in views directory "/home/USER/Desktop/scholarship-app/views"

here my part of my express app code

app.get('/phd/:id', function(req, res) {

    var pdhID = parseInt(req.params.id, 10);
    var query = req.query;

    console.log('console: ' + pdhID + 'query: ' + query);

    db.scholarship.findAll({

        where: pdhID
    }).then(function(scholarship) {

        if (scholarship != null) {

            if (query.hasOwnProperty('format') && query.format === 'json') {

                return res.json(scholarship);
            } else {

                var data_scholarship = JSON.stringify(scholarship);
                console.log("rendering the scholarship page" +  data_scholarship );
                //error
                return res.render('/id', {

                    title: data_scholarship.title,
                    css_path: '/public/css/styles.css',
                    keywords: 'phd position, shoclarships for sciences',
                    menu_bar_arr: menu_bar_arr,
                    menu_bar_link: menu_bar_link,
                    current_page: 'about-us',
                    menu_bar_lindx: menu_bar_arr.length - 1,
                    data_scholarship: data_scholarship,
                    error: 0
                });
            }
        } else {

            return res.render('id', {
                error: '404'
            });
        }
    }, function(err) {

        return res.render('id', {
            msg: 'could cnt open the file',
            error: 1
        });
    });
});

My id.ejs file is located @ path /home/USER/Desktop/scholarship-app/views, still it giving me the error.

It will be great if some one can help it the error. My other view in the same directory is getting render properly

Answers to

Express app with EJS template giving Error: Failed to lookup view "/id" in views directory "/home/USER/Desktop/scholarship-app/views"

nr: #1 dodano: 2017-01-05 10:01

Remove extra / from your id in return res.render('/id',{....})

Source Show
◀ Wstecz