node.js - 为什么我的主页在发布后不显示?
问题描述
所以我试图index.ejs
在发布后重定向回页面newPost.ejs
。上传工作,但它永远不会重定向回来。点击后只留下一个持续加载页面Post
我假设我的路线或 ejs 有问题。
这是我的发帖路线:
app.post('/newPost', isLoggedIn, uploads.single('inputFile'), (req, res) => {
console.log('On POST route');
// get an input from user
let file = req.file.path;
console.log(file);
cloudinary.uploader.upload(file, (result) => {
console.log(result);
db.post.create({
caption: req.body.title,
image_url: result.url,
userId: req.body.id
})
// Render result page with image
}).then((post) => res.render('index', { image: result.url }));
})
这是我的获取路线:
app.get('/', (req, res) => {
console.log(res.locals.alerts);
db.post.findAll()
.then((posts) => {
const postArray = posts.map(post => {
return post.get();
})
console.log(postArray);
res.render('index', { posts: postArray });
})
});
这是index.ejs
:
<div>
<% posts.forEach(function(post) { %>
<h1></h1>
<img class="images" width="700px" height="500px" src="<%= post.image_url %>" alt="uploaded image">
<form action="/<%= post.id %>?_method=DELETE" method="POST">
<input id="deleteButton" class="btn-danger" type="submit" value="Remove idea" >
</form>
<br>
<% }) %>
</div>
最后,这是我的newPost.ejs
<div class="postSection">
<form action="/" method="POST" enctype="multipart/form-data">
<input type="title" placeholder="Write a Caption:" id="postText">
<input type="file" name="inputFile" id="inputFile">
<input type="submit" class="btn btn-primary" id="postSubmit" value="Post">
</form>
</div>
解决方案
推荐阅读
- python - OpenCV 从采集卡或 OBS Studio FaceRecogition 加载视频
- gtk - 如何从 gedit 中的活动窗口访问整个文档
- java - SQLite - 没有这样的表:使用 CTE 删除重复记录时
- emq - 如何配置 emqtt 的最大数据包大小
- sql - 如何对查询 SQL 进行多项选择?
- android - ANDROID:点击锁屏通知时生命周期无法正常工作
- c# - 提示 linq 2 sql 需要用于 linq 对象属性的列
- python - Conda install some-package 挂起(解决环境:失败)
- sql - 使用 between 语句查询包含数字的 SQL 列 varchar6
- javascript - 是否可以通过指定索引数组来访问数组的第 n 个深度元素?