📜  createview - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:36.646000             🧑  作者: Mango

代码示例1
# Required imports
from django.urls import reverse_lazy

class YourView(CreateView):
    model             = Model
    fields             = ['your_fields']
    template_name     = 'your_template'
    success_url        = reverse_lazy('home')
    
    def form_valid(self, form):
        form.instance.user = self.request.user
        super(YourView, self).form_valid(form)
        return redirect('home')