'Django NoReverseMatch: Reverse for 'add_continue' with arguments '('',)'

Anyone know what could be causing this error I'm getting? Most of the other code, which works the exact same way, works perfectly. However, this button doesn't work whenever I click it for some reason. The error only happens once the button to add a movie to a watchlist is clicked. I've checked out some of the other suggestions on here and none of them seem directly correlated to this issue. Any suggestions?

Here is the error:

NoReverseMatch at /watchlist/
Reverse for 'add_continue' with arguments '('',)' not found. 1 pattern(s) tried: ['resumeMovie/add/(?P<film_id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/$']

Watchlist.html:

{% extends "base.html" %} {% load static %} {% block metadescription %} This is
the watchlist page. Proceed to review your items. {% endblock %} {% block title
%} Watchlist - MovieBuff {% endblock %} {% block content %} {% if not
watchlist_items %}
<div>
  <div class="text-center">
    <br />
    <h1 class="text-center my_title">Your watchlist is empty</h1>
    <br />
    <p class="text-center">
      Please click <a href="{% url 'movies:allFilmGenre' %}">here</a> to
      continue browsing our collection.
    </p>
  </div>
</div>
{% else %}
<div>
  <div class="text-center">
    <br />
    <h1 class="text-center my_title">Your Watchlist</h1>
    <br />
  </div>
</div>
<div class="row mx-auto">
  <div class="col-12 col-sm-12 col-md-12 col-lg-6 text-center">
    <table class="table my_custom_table">
      <thead class="my_custom_thead">
        <tr>
          <th colspan="5">Your Films to watch</th>
        </tr>
      </thead>
      <tbody>
        {% for watchlist_item in watchlist_items %}
        <tr class="my_custom_thead">
          <td>
            <a href="{{watchlist_item.film.get_absolute_url}}"
              ><img
                src="{{watchlist_item.film.image.url}}"
                alt=""
                class="float-left rounded custom_image"
            /></a>
          </td>
          <td class="text-left">
            {{watchlist_item.film.name}}
            <br />
            Film Price: €{{watchlist_item.film.price}}
            <br />
          </td>

          {% if watchlist_item.quantity < watchlist_item.film.stock %}
          <td>
            <a
              href="{% url 'watchlist:watchlist_remove' watchlist_item.film.id %}"
              class="btn btn-secondary btn-block my_custom_button"
              >Already Watched</a
            >
            <a
              class="btn btn-secondary"
              href="{% url 'resumeMovie:add_continue' continue_item.film.id %}"
              >Watch Movie</a
            >
          </td>
          <td></td>

          {% else %}
          <td>
            <a
              href="{% url 'watchlist:full_remove' watchlist_item.film.id %}"
              class="btn btn-secondary btn-block my_custom_button"
              >Already Watched</a
            >
            <a
              href="{% url 'resumeMovie:full_remove' continue_item.film.id %}"
              class="btn btn-success btn-block"
              >Finish Watching</a
            >
          </td>
          <td></td>
          {% endif %}
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
</div>
<br />
{% endif %} {% endblock %}

views.py:

def _watchlist_id(request):
    watchlist = request.session.session_key
    if not watchlist:
        watchlist = request.session.create()
    return watchlist


def add_watchlist(request, film_id):
    film = Film.objects.get(id=film_id)
    try:
        watchlist = Watchlist.objects.get(watchlist_id=_watchlist_id(request))
    except Watchlist.DoesNotExist:
        watchlist = Watchlist.objects.create(
                watchlist_id=_watchlist_id(request)
            )
        watchlist.save()
    try:
        watchlist_item = WatchlistItem.objects.get(film=film, watchlist=watchlist)
        if watchlist_item.quantity < watchlist_item.film.stock:
            watchlist_item.quantity += 1
        watchlist_item.save()
    except WatchlistItem.DoesNotExist:
        watchlist_item = WatchlistItem.objects.create(
                        film = film,
                        quantity = 1,
                        watchlist = watchlist
        )
        watchlist_item.save()
    return redirect('watchlist:watchlist_detail')

def watchlist_detail(request, total = 0, counter=0, watchlist_items=None):
    try:
        watchlist = Watchlist.objects.get(watchlist_id=_watchlist_id(request))
        watchlist_items = WatchlistItem.objects.filter(watchlist=watchlist, active=True)
        for watchlist_item in watchlist_items:
            total += (watchlist_item.film.price * watchlist_item.quantity)
            counter += watchlist_item.quantity
    except ObjectDoesNotExist:
        pass
    return render(request, 'watchlist.html', {'watchlist_items':watchlist_items, 'counter':counter})

def watchlist_remove(request, film_id):
    watchlist = Watchlist.objects.get(watchlist_id=_watchlist_id(request))
    film = get_object_or_404(Film, id=film_id)
    watchlist_item = WatchlistItem.objects.get(film=film, watchlist=watchlist)
    if watchlist_item.quantity > 1:
        watchlist_item.quantity -= 1
        watchlist_item.save()
    else:
        watchlist_item.delete()
    return redirect('watchlist:watchlist_detail')


def full_remove(request, film_id):
    watchlist = Watchlist.objects.get(watchlist_id=_watchlist_id(request))
    film = get_object_or_404(Film, id=film_id)
    watchlist_item = WatchlistItem.objects.get(film=film, watchlist=watchlist)
    watchlist_item.delete()
    return redirect('watchlist:watchlist_detail')

def _continue_id(request):
    resume = request.session.session_key
    if not resume:
        resume = request.session.create()
    return resume


def add_continue(request, film_id):
    film = Film.objects.get(id=film_id)
    try:
        resume = Resume.objects.get(continue_id=_continue_id(request))
    except Resume.DoesNotExist:
        resume = Resume.objects.create(
                continue_id=_continue_id(request)
            )
        resume.save()
    try:
        continue_item = ResumeItem.objects.get(film=film, resume=resume)
        if continue_item.quantity < continue_item.film.stock:
            continue_item.quantity += 1
        continue_item.save()
    except ResumeItem.DoesNotExist:
        continue_item = ResumeItem.objects.create(
                        film = film,
                        quantity = 1,
                        resume = resume
        )
        continue_item.save()
    return redirect('resumeMovie:continue_detail')

def continue_remove(request, film_id):
    resume = Resume.objects.get(continue_id=_continue_id(request))
    film = get_object_or_404(Film, id=film_id)
    continue_item = ResumeItem.objects.get(film=film, resume=resume)
    if continue_item.quantity > 1:
        continue_item.quantity -= 1
        continue_item.save()
    else:
        continue_item.delete()
    return redirect('resume:continue_detail')


Solution 1:[1]

Is continue_item available in the template context, it might be missing. Try to print it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abhinay Yadav