hey there
i’m working on a social media project for practice and i keep getting an error
i have created views and Forms to create an update the posts
i get the WSGIRequest for the line of 64
and i wonder why i dont get the error for i just did in line 52
Please don’t post image of code, post the code itself using the tools for formatting code.
If you look closely on line 68, you’ll see that you have misarranged the parameters on their positions, and they ended up swapped.
You probably want to have self
as the first parameter for that function.
thanks for answer
but i rearranged them the way you said but the same error occured
class PostCreateView(LoginRequiredMixin , View):
form_class = PostCreateUpdateForm
def get(request , self , *args , **kwargs):
form = self.form_class
return render(request , 'home/post_create.html' , {'form':form})
def post(self , request , *args , **kwargs):
form = self.form_class(request.POST)
if form.is_valid():
new_post = form.save(commit = False)
new_post.slug = slugify(form.cleaned_data['body' , ][:30])
new_post.user = request.user
new_post.save()
messages.success(request , 'new post created' , 'success')
return redirect('home:page_detail' , new_post.id , new_post.slug)
- This order of the parameters in the
get
definition is still not correct.
- The second line is getting a reference to the
form_class
class, and is not creating an instance of the form.
Notice the difference between your definition above, and this:
This reference is creating an instance of the form_class
object.