내 응용 프로그램의 디렉토리 구조 :express.static (__이 dirname + '공개 /')가 작동하지 않습니다
app
-views
-index.html
-article.html
-public
-stylesheet.js
그리고 내 코드 :
var express = require('express');
var app = express();
var hbs = require('hbs');
var blogEngine = require('./blog');
app.set('view engine', 'html');
app.engine('html', hbs.__express);
app.use(express.json(), express.urlencoded());
app.use(express.static(__dirname+'/public'));
app.get('/', function(req, res) {
res.render('index',{title:"My Blog", entries:blogEngine.getBlogEntries()});
});
app.get('/article/:id', function(req, res) {
var entry = blogEngine.getBlogEntry(req.params.id);
res.render('article',{title:entry.title, blog:entry});
});
app.listen(8888);
사용 localhost:8888
의 stylesheet.js이 잘로드 . 그러나 localhost:8888/article.html
을 사용하면 스타일 시트가로드되지 않습니다. (인덱스 페이지 제외) 스타일 시트
TypeError: Cannot read property 'title' of undefined
왜 entry.title
입니다 undefined
: 나는 article.html
파일에 {{title}}
작품을 따라하지만 스타일 시트의 코드를 참조 할 때, 나는 오류 텍스트를 볼 수?
article.html의 형식은 무엇입니까? – mscdex
{{blog.title}} 게시
: {{blog.published} } {{blog.body}} – Rejaul@mscdex 감사합니다. 그것은/stylesheet.css와 작동합니다. – Rejaul