How to subclass django's generic CreateView with initial data?

后端 未结 3 1741
故里飘歌
故里飘歌 2020-12-13 05:11

I\'m trying to create a dialog which uses jquery\'s .load() function to slurp in a rendered django form. The .load function is passed the pk of the \"alert\" object. Also av

3条回答
  •  感情败类
    2020-12-13 05:36

    you can use like :

    from django.shortcuts import HttpResponseRedirect
    
        class PostCreateView(CreateView):
            model = Post
            fields = ('title', 'slug', 'content', 'category', 'image')
            template_name = "create.html"
            success_url = '/'
    
            def form_valid(self, form):
                self.object = form.save(commit=False)
                self.object.user = self.request.user
                self.object.save()
                return HttpResponseRedirect(self.get_success_url())
    

    that's work for me

提交回复
热议问题