8 글 보임 - 1 에서 8 까지 (총 8 중에서)
-
글쓴이글
-
2022년 9월 11일 18:33 #46097
박승은참가자강의에서는 app.post('/add', function(req, res){ res.send('전송완료') 이렇게 /add 페이지에서 메시지를 보내게 하셨는데 예를들어 index 페이지와 연결하고 싶은경우 app.post('/', function(req, res){ res.render('index.ejs') 이렇게 하면 오류가 나는데 어떻게 코딩해야 하나요?
2022년 9월 12일 02:17 #46141
박승은참가자그래서 원하는 페이지로 링크하려면 form action에 /원하는링크 적고 app.post('/원하는링크', function(req, res){ res.render('링크파일.ejs')
이거 아닌가요? 계속 오류가 나서 이유를 모르겠습니다 ㅠ
2022년 9월 12일 13:35 #46162
박승은참가자아 죄송합니다 질문 바꾸겠습니다 post요청으로 글을 쓰면 그 글 상세페이지로 이동시키려고 하는데요 글쓰기 페이지는 write.ejs 상세페이지는post.ejs 글이 저장된 db명은 list 입니다 <form action="/post/<%= Post[i]._id%>" method="POST"> <div class="form-group"> <label for="" class="label-title">제목</label> <input type="text" class="input-title" name="title" placeholder="제목을 입력하세요"> </div> <button type="submit" id="submit">완료</button> </form> ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ app.get('/write', function(req,res){ db.collection('list').find().toArray(function(error,result){ res.render('write.ejs', { Post: result}); }); })
app.post('/post/:id', function(req, res){ res.render('post.ejs') db.collection('counter').findOne({name : '게시물갯수'}, function(error, result){ console.log(result.totalPost) var 총게시물갯수 = result.totalPost; db.collection('list').insertOne( {_id : 총게시물갯수 +1, 제목 : req.body.title}, function(error,result){
db.collection('list-counter').updateOne({name:'게시물갯수'},{$inc : {totalPost:1}},function(error,result){ if(error){return console.log(error)} }) }); }); });
app.get('/post/:id', function(req,res){
db.collection('list').findOne({_id : parseInt(req.params.id)}, function(error,result){ console.log(result) res.render('post.ejs', { data : result }); }) });
이렇게 하면 에러가 나는데 이유를 모르겠습니다..
2022년 9월 12일 16:32 #46186
codingapple키 마스터res.render('post.ejs')를 if(error){return console.log(error)} 밑으로 옮깁시다
-
글쓴이글
8 글 보임 - 1 에서 8 까지 (총 8 중에서)
- 답변은 로그인 후 가능합니다.