django - 为什么我的文字帖子无法保存,它以前工作过?
问题描述
我的文本帖子在添加通知功能之前可以正常工作,但现在不行了,我有一个调试打印但没有看到帖子对象,而是看到了发布它的用户。除了获取帖子 ID 和通知功能外,我没有更改任何内容 timesince
,我对图片和视频帖子使用了完全相同的方法,它们工作正常,所以对我来说没有意义。我在通知功能中有一个调试打印,以确保帖子类型和 id 已正确传递,并且确实显示了 id 和类型
视图.py
@login_required()
def text_post(request):
if request.method == "POST":
form = TextPostForm(request.POST)
if form.is_valid():
t_post = form.save(commit=False)
t_post.author = request.user
t_post.save()
id = t_post.id
time = timesince
print(t_post) # t_post shows the user instead of the post
followers = list(request.user.followers.all())
notify(followers,
request.user,
f"{request.user.username} posted {time}",
id,
'text'
)
print(t_post)
#redirect to last page
return redirect('home')
else:
form = TextPostForm()
post_type = 'text'
return render(request, 'create_post.html', {'form': form, 'post_type': post_type})
表格.py
class TextPostForm(forms.ModelForm):
class Meta:
model = TextPost
fields = ('description','privacy', 'categories')
解决方案
推荐阅读
- java - 无法使用 Kubernetes Java 客户端将 volumeMounts 设置为特定容器
- c++ - __attribute__((packed)) 的性能影响,是否仅对涉及“打包”结构的指令存在性能影响?
- javascript - 当 JSON 在值中包含“'”元素时服务器错误 400
- python - dict.items() 函数
- vba - 使用 Item_Add 将两个结果之一应用于传入电子邮件
- c++ - 通过vcpkg和cmake安装后如何生成c++ grpc文件?
- typescript - combineReducers 返回类型被推断为任何类型
- python - 将 help() 的内容存储在一个变量中:Python
- jquery - 即使没有带有dropzone js的图像,也可以在mysql中插入数据
- javascript - 当我单击按钮时,innerHTML 中的函数无法正常工作