Example #1
0
 def post(self, request):
     form = forms.PostForm(request.POST, request.FILES)
     if form.is_valid():
         newpost = form.save(commit=False)
         newpost.user = request.user
         newpost.save()
         return redirect('/home')
Example #2
0
 def post(self, request):
     form = forms.PostForm(request.POST, request.FILES)
     if form.is_valid():
         # creating django like model without saving to database
         post = form.save(commit=False)
         post.user = request.user
         post.save()
     return redirect('/home/')
Example #3
0
    def post(self, request):
        form = forms.PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.user = request.user
            post.save()

        return redirect('/home/')
Example #4
0
 def get_context_data(self, *args, **kwargs):
     data = super().get_context_data(*args, **kwargs)
     data['post_form'] = forms.PostForm()
     return data