python - Django:在 def post() 中返回与 PostListView 相同的数据
问题描述
有没有一种简单的方法可以让我使用 PostListView 在 post 方法中返回相同的数据?
class PostListView(ListView):
model = Post
template_name = 'blog/home.html'
context_object_name = 'posts'
ordering = ['-date_posted']
paginate_by = 5
def post(self, request, *args, **kwargs):
*create like in db*
*flash message*
return *same data as get request*
我有一个简单的 Instagram 副本应用程序,此帖子列表视图显示所有帖子。每个帖子都有一个赞按钮。如果用户单击此按钮,它将在 db 中创建一个新的类似对象并显示一条闪烁消息。之后,我想显示与单击按钮之前相同的数据。有没有办法这样做?
解决方案
推荐阅读
- java - 为什么 postRotate() 方法改变 X 轴方向
- c# - 无法通过 Web 服务在数据库中创建用户和更新用户
- dns - 如何解决此错误“NotServedByPagesError”
- swiftui - iPad 纵向模式下的拆分视图会导致启动时显示无用的视图
- r - 防止某些元素在 for 循环中被 `sample()`ed
- sql - 在连接到 BigQuery 的 Google 工作表中将表旋转并连接到自身
- service - 想要从 .NET 辅助服务启动一个长时间运行的程序
- javascript - 根据时间范围过滤 JSON 数据以返回介于每周间隔之间的数据
- reactjs - Redux 工具包在 api 响应上更新状态
- python - Jupyter笔记本中的XGBoost dlsym问题