I want to update my database with Django.
Specifically, when you press the "+1" button on the browser, the number will be incremented by 1 on the database and I want to display that number on the browser.
Example) Original number is 1 → Press button → Database is updated and 1 becomes 2 → 2 is displayed on the browser.
I'm glad if you answer me because it's packed for 3 or 4 days.
I think that there are many points that do not come, but thank you.

Error message Even if the

button is pressed, it is not done after updating the numbers in the database.

Applicable source code blog/models.py
from django.conf import settings
from django.db import models
from django.utils import timezone

class Post (models.Model):
    author = models.ForeignKey (settings.AUTH_USER_MODEL, on_delete = models.CASCADE)
    title = models.CharField (max_length = 200)
    #I want to manage this up_number
    up_number = models.IntegerField (default = 0)
    published_date = models.DateTimeField (blank = True, null = True)
    def publish (self):
        self.published_date = timezone.now ()
        self.save ()
from django.urls import path
from .import views
urlpatterns = [
    path ('', views.post_list, name = 'post_list'),
    path ('post/<int: pk>/post_form /', views.post_form, name = 'post_form'),
{% for post in posts%}
       <form action = "{% url 'post_form' pk = post.pk%}" method = "POST">
    {% csrf_token%}
           <input type = "submit" value = "+ 1">
{% endfor%}
from django.shortcuts import render
from django.utils import timezone
from .forms import PostForm
from .models import Post
def post_list (request):
    posts = Post.objects.filter (published_date__lte = timezone.now ()). order_by ('published_date')
    return render (request, 'blog/post_list.html', {'posts': posts})
#I don't know
def post_form (request):
    if request.method == 'POST':
        post = get_object_or_404 (Post, pk = pk)
        post.up_number + = 1
        post.save ()
    return render (request, 'blog/post_list')
Supplemental information (FW/tool version etc.)

OS Windows10
python 3.7.3
Django 2.2.6

  • Answer # 1

    I will post more details later.
    Thank you all for watching.