Q:

editing post, it almost works but when I click final edit button it takes me to 404 page, why? ( deleting works fine)

I have this code
class PostUpdateView(UpdateView):
     model = Post
     form_class = PostForm
     template_name = 'main/edit.html'

     def form_valid(self, form):
            self.object = form.save(commit=False)
            # Any manual settings go here
            self.object.save()
            return HttpResponseRedirect(self.object.get_absolute_url())

     @method_decorator(login_required)
     def dispatch(self, request, *args, **kwargs):
        post = Post.objects.get(slug=kwargs['slug'])
        if post.moderator == request.user:
            return super(PostUpdateView, self).dispatch(request, *args, **kwargs)
        else:
            return http. HttpForbidden()

It almost works, only user that posted can edit and I followed the same method for deleting and it works fine.  I'm just not sure why it won;t work for editing the form.  when the user goes to edit url, it shows the editing form which is same as post form.  but when the user clicks edit button it takes me to http://127.0.0.1:8000/edit/ which doesn't exist.but editing url is http://127.0.0.1:8000/post/xx/edit/ .  As I write this question I realize I have this in my edit.html <form id="post_form" method="post" action="/edit/" enctype="multipart/form-data">
 should I change action?  for adding post  the action is "/add_post/"

A:

The action in the form is the url that the form data will be submitted to.  You have,
<form id="post_form" method="post" action="/edit/" enctype="multipart/form-data">

so the form will be submitted to the url /edit/.
To submit the form to /post/xx/edit/, you can do
<form id="post_form" method="post" action="/post/{{ post.id }}/edit/" enctype="multipart/form-data">

If the edit URL is the same as the post's absolute URL, you can do
<form id="post_form" method="post" action="{{ post.get_absolute_url }}" enctype="multipart/form-data">

If you are submitting to the current url, you can leave out the action completely. 
<form id="post_form" method="post" enctype="multipart/form-data">

