title: Image ids apparently not being created
body: <p>I have created a template for displaying a photo gallery and giving users the ability to add photos to that gallery:</p>
  
  <pre class="lang-html prettyprint-override"><code>{% extends 'nowandthen/base.html' %}
  {% block body_block %}
  &lt;br&gt;
  &lt;br&gt;
  {% if pictures %}
      &lt;ul&gt;
      {% for p in pictures %}
  &lt;div class="container"&gt;
    &lt;div class="row"&gt;
      &lt;div class="col-md-8 card mb-4  mt-3 "&gt;
          &lt;!-- Card --&gt;
  
    &lt;!-- Card content --&gt;
              &lt;div class="card-body d-flex flex-row"&gt;
  
      &lt;!-- Content --&gt;
                  &lt;div&gt;
  
        &lt;!-- Title --&gt;
                      &lt;h4 class="card-title font-weight-bold mb-2"&gt;{{ p.title }}&lt;/h4&gt;
        &lt;!-- Subtitle --&gt;
                      &lt;p class="card-text"&gt;&lt;i class="far fa-clock pr-2"&gt;&lt;/i&gt;{{ p.when_added }}&lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
    &lt;!-- Card image --&gt;
              &lt;div class="view overlay"&gt;
                  &lt;img class="card-img-top rounded-0" src="{{ p.image.url }}" alt="Card image cap"&gt;
                      &lt;a href="#!"&gt;
                          &lt;div class="mask rgba-white-slight"&gt;&lt;/div&gt;
                      &lt;/a&gt;
              &lt;/div&gt;
  
    &lt;!-- Card content --&gt;
              &lt;div class="card-body"&gt;
                  &lt;div class="collapse-content"&gt;
  
        &lt;!-- Text --&gt;
                      &lt;p class="card-text collapse" id="collapseContent"&gt;{{ p.description }}&lt;/p&gt;
        &lt;!-- Button --&gt;
                      &lt;a class="btn btn-flat red-text p-1 my-1 mr-0 mml-1 collapsed" data-toggle="collapse" href="#collapseContent" aria-expanded="false" aria-controls="collapseContent"&gt;Click for description&lt;/a&gt;
                      &lt;i class="fas fa-share-alt text-muted float-right p-1 my-1" data-toggle="tooltip" data-placement="top" title="Share this post"&gt;&lt;/i&gt;
                      &lt;i class="fas fa-heart text-muted float-right p-1 my-1 mr-3" data-toggle="tooltip" data-placement="top" title="I like it"&gt;&lt;/i&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="card-body"&gt;
          &lt;!-- comments --&gt;
                  &lt;h2&gt;comments&lt;/h2&gt;
                  {% if not p.comments %}
                  No comments
                  {% endif %}
                  {% for x in p.comment %}
                  &lt;div class="comments" style="padding: 10px;"&gt;
                      &lt;p class="font-weight-bold"&gt;
                          &lt;h4&gt;Comment by&lt;/h4&gt; {{ x.user }}
                          &lt;span class=" text-muted font-weight-normal"&gt;
                              {{ x.created_on }}
                          &lt;/span&gt;
                      &lt;/p&gt;
                      {{ x.body | linebreaks }}
                  &lt;/div&gt;
                  {% endfor %}
              &lt;/div&gt;
              &lt;div class="card-body"&gt;
                  {% if new_comment %}
                  &lt;h2&gt;Your comment has been posted.&lt;/h2&gt;
                  {% else %}
                  &lt;h3&gt;Leave a comment&lt;/h3&gt;
                  &lt;form action="{% url 'nowandthen:add_comment' p.image_id %}" method="POST"&gt;
                      {{ comment_form.as_p }}
                      {% csrf_token %}
                      &lt;button type="submit" class="btn btn-primary  btn-lg"&gt;Submit&lt;/button&gt;
                  {% endif %}
              &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- Card --&gt;
      {% endfor %}
      &lt;/ul&gt;
  {% else %}
      &lt;li&gt;&lt;strong&gt;There are no photographs present.&lt;/strong&gt;&lt;/li&gt;
  {% endif %}
  
  {% endblock %}
  </code></pre>
  
  <p>The idea is that there is an image associated with each comment - there is a for loop of {% for p in pictures %} at the start of the page, and I use variations of p. (e.g. p.image_id) to associate particular pictures with particular comments. </p>
  
  <p>In addition, the urls.py contains the following:</p>
  
  <pre><code>path('add_comment/&lt;int:p.image_id&gt;', views.add_comment, name='add_comment')
  </code></pre>
  
  <p>However, when I run the code, I get an error message that suggests that image ids aren't being created (even though image is a field in he Pictures model I created): </p>
  
  <p><strong>Reverse for 'add_comment' with arguments '('',)' not found. 1 pattern(s) tried: ['add_comment/$']</strong></p>
  
  <p>What do you suggest, please?</p>
  
  <p>EDIT: This is my view: </p>
  
  <pre><code>@login_required
  def add_comment(request, image_id):
  new_comment = None
  template_name = 'add_comment.html'
  image = get_object_or_404(Picture, id=image_id)
  comment = image.comments.filter(active=True)
  new_comment = None
  # Comment posted
  if request.method == 'POST':
      comment_form = CommentForm(data=request.POST)
      if comment_form.is_valid():
          # Create Comment object and don't save to database yet
          new_comment = comment_form.save(commit=False)
          # Assign the current post to the comment
          new_comment.post = post
          # Save the comment to the database
          new_comment.save()
  else:
      comment_form = CommentForm()
  
  context = {'image': image,'comment': comment, 'new_comment': new_comment,'comment_form': comment_form}
  
  return render(request, template_name, context)
  </code></pre>
  
  <p>And this is my add_comment.html template:</p>
  
  <pre class="lang-html prettyprint-override"><code>
  {% extends 'nowandthen/base.html' %}
  {% load staticfiles %}
  {% block title_block %}
  Add self
  {% endblock %}
  {% block body_block %}
  &lt;h1&gt;Add a Comment&lt;/h1&gt;
  &lt;div&gt;
  &lt;form id="comment_form" method="post" action="{% url 'nowandthen:add_comment' comment_id%}" enctype="multipart/form-data" &gt;
  {% csrf_token %}
  {{ form.as_p }}
  &lt;input type="submit" name="submit" value="Add Comment" /&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  {% endblock %}
  
  </code></pre>