Django Class Based Views, get_absolute_url not working

后端 未结 5 1407
闹比i
闹比i 2021-02-10 17:57

I bought and am Reading the Book Two Scoops of Django:Best Practices for Django 1.5 and in it has a example of Class based views. After this implementation I get the error afte

5条回答
  •  一生所求
    2021-02-10 18:13

    Solved the problem after reading the first sentence of Austin Phillips:

        def form_valid(self, form):
            article = form.save(commit=False)
            article.author = self.request.user
            self.object = article.save()
            return super().form_valid(form)
    

    the point is the save article.save()'s result back to self.object

提交回复
热议问题