i can post my data but cannot show it with body-parser

64 views Asked by At

I have a website project. I have a form for daily-program and I want to show it in another tab.

 <form action="/posts/test" method="POST" enctype="multipart/form-data"> 
    //htmlcodes
 </form>

And I am getting data with:

router.post("/daily_prog" , (req,res) => {
    let daily_image = req.files.daily_image
    daily_image.mv(path.resolve(__dirname, "../../public/img/dailyimages", daily_image.name))


    Daily.create({
        ...req.body,
        daily_image: `/img/dailyimages/${daily_image.name}`,
        
    },)
    req.session.sessionFlash={
        type: "alert alert-success",
        message: "Successfully done."
    }
    console.log(req.body)
    res.redirect("/daily")
})

And with console.log, I can see all of my data in my terminal which I just posted with the form. Now I want to show it in a tab of "Daily" with the following code, but it does not appear.

The router:

router.get("/daily",(req,res)=>{
    Daily.find({}).lean().then(daily =>{
        res.render("site/daily",{daily:daily})
    })
})

And the HTML page markup which I want to display my data:

                    {{#each daily}}
                    <div class="col-md-6">
                        <div class="blog">
                            <div class="blog-img">
                                <img src="{{daily_image}}" class="img-fluid">
                            </div>
                            <div class="blog-content">
                                <ul class="blog-meta">
                                    <li><i class="fas fa-users"></i><span class="writer">{{daily_content}}</span></li>
                                    <li><i class="fas fa-clock"></i><span class="writer">{{daily_content}}</span></li>
                                    <li><i class="fas fa-comments"></i><span class="writer"></span></li>
                                </ul>
                                <h3>{{daily_title}}</h3>
                                <p>{{daily_content}}</p>
                                
                                
                            </div>
                        
                        </div>
                        
                    </div>
                    {{/each}}

When I use {{#each}} and {{/each}}, all the HTML between these tags is missing in the display. If I do not use them and just try to display without them, then also any dynamic data never appear.

0

There are 0 answers