Q: How to pass a value from anchor tag to a function in views in Django I have a model object movie and I want to pass movie.mid to addmovie function in views
views.py
def addMovie(request, mid):
    uid = request.user.id
    ob = MyMovies.objects(uid=uid, mid=mid, watched=True)
    ob.save();
    return redirect('/')

urls.py
path('addmovie/<int:mid>/', views.addMovie, name="addmovie"),

index.html
{% if movies %}
    <section id="main">
        <h2 class="latest-heading">Movies</h2>
        <ul id="autoWidth2" class="cs-hidden">
            {% for movie in movies %}
                <li class="item-a">
                    <div class="latest-box">
                        <div class="latest-b-img">
                            <!-- <a href="{% url 'movieinfo' %}" title=""> -->
                            <img src={{ movie.cover }}>
                            <!-- </a> -->
                        </div>
                        <div class="latest-b-text">
                            <strong>{{movie.title}}</strong>
                            <p>{{movie.rdate}}</p>
                        </div>
                        {% if user.is_authenticated %}
                            <div>
                                <a href="{% url 'addmovie' movie.mid %}" style="color:chocolate;">Add to watched</a>
                            </div>
                            <br>
                        {% endif %}
                    </div>
                </li>
            {% endfor %}
        </ul>
    </section>
{% endif %}

Even After passing the values correctly, the values in MyMovies are not updating. What am I doing wrong?

A: you need to add movie.mid after url name, like <a href="{% url 'addmovie' movie.mid %}" style="color:chocolate;">Add to watched</a></div>
then, movie.mid will pass to url.py. And you need to add a parameter on url.py.
url.py
path('addmovie/<int:mid>/',views.addmovie)

then you need to pass to views.py
def addmovie(request,mid):


A: def addMovie(request, mid):
   if request.method == "POST":
      mid = request.POST['data'] # the problem is here, you are overriding mid default value
      uid = request.user.id
      try:
         my_movie = MyMovies.objects.get(mid=mid)
         my_movie.watched = True
      except:
         my_movie = MyMovies(uid=uid, mid=mid, watched=True)
      my_movie.save()
      return redirect('/')

