[英]Django CreateView does not saving and loading the success url after submit
Hello i have been working on django CreateVeiw.您好,我一直在研究 django CreateVeiw。 As i have add tags and save my post form.因为我添加了标签并保存了我的帖子表单。 But the problem is after i click submit it just reload the page and when i check on my post it didnt add also.但问题是在我点击提交后它只是重新加载页面,当我检查我的帖子时它也没有添加。 Did i miss something out?我错过了什么吗? Can someone answer me?有人可以回答我吗? This is my view of creating post.这是我对创建帖子的看法。
class PostCreate(CreateView):
template_name = 'add_post.html'
model = Post
form_class = PostForm
def form_valid(self, form):
form.instance.user = self.request.user
form = form.save(commit=False)
form.slug = slugify(form.title)
form.save()
form.save_m2m()
return super(PostCreate, self).form_valid(form)
def get_success_url(self):
return reverse('article-list', args=self.object.id,)
Thanks in advance :).提前致谢 :)。
Have you tried:你有没有尝试过:
def form_valid(self, form):
super().form_valid(form)
. . .
form.save()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.