Home > Software engineering >  Updating post is not saving in the database
Updating post is not saving in the database

Time:11-16

hello i'm a beginner to django, i made an edit button where i can edit a post, but the problem is it's not saving in the database[[enter image description here](https://i.stack.imgur.com/ZEtVa.png)](https://i.stack.imgur.com/mfr8g.png)

i tried everything i could went to youtube but nothing

CodePudding user response:

I would use class based views. They are much simpler and less headache. This is how they work. More info here

In your urls you have to add .as_view()

from .views import UpdateView
path('post/<pk>/update', UpdatePost.as_view()),

in views.py

from django.views.generic import UpdateView
class UpdatePost(UpdateView):
    template_name = "update_post.html"
    model = Post
    form = YourForm() or Fields = ["title", "content", "whatever you named them in your models"]
    success_url ="/"
  • Related