title: Slug URL turns into a number when navigating to the next link in django
body: <p>I tried searching for this problem here but I didn't find anything, I hope someone can help answering or sending a link to a solution on stackoverflow...</p>
  <p>I have been creating a blog, and when I click on the post title, it goes to 'post_details.html' and in the URL shows a slug with the post title. Like here:</p>
  <blockquote>
  <p>examplename.com/blog/brooklyn-nets-at-miami-heat-preview/</p>
  </blockquote>
  <p>But when I click to write a comment on the post it takes me to a form page, but the slug title disappear, it just shows the post number. Like this:</p>
  <blockquote>
  <p>examplename.com/blog/3/add-comment</p>
  </blockquote>
  <p>Can someone explain why is this happening? I want to know how to solve this and understand from where it comes this number that shows up.</p>
  <p><strong>Post_detail.html</strong></p>
  <pre><code>{% block content %}
  &lt;h2 class=&quot;title&quot;&gt;
      &lt;a class=&quot;post-title&quot; href=&quot;{{ post.get_absolute_url }}&quot;&gt;
          {{ post.title }}
      &lt;/a&gt;
  &lt;/h2&gt;
  &lt;p class=&quot;date&quot;&gt;
      Publicado em {{ post.created }} por {{ post.author }}
  &lt;/p&gt;
  {{ post.body|linebreaks }}
  &lt;hr&gt;
  &lt;h3&gt;Comments&lt;/h3&gt;
  {% if not post.comments.all %}
      Nobody commented yet...&lt;a href=&quot;{% url 'blog:commentview' post.pk %}&quot;&gt;Add a comment&lt;/a&gt;
  {% else %}
      &lt;a href=&quot;{% url 'blog:commentview' post.pk %}&quot;&gt;Add a comment&lt;/a&gt;
      {% for comment in post.comments.all %}
          {{ comment.name }}
          {{ comment.date }}
          &lt;br&gt;
          {{ comment.body }}
      {% endfor %}
  {% endif %}
      &lt;a class=&quot;swen&quot; href=&quot;{% url 'blog:list' %}&quot;&gt;More Articles&lt;/a&gt;
  {% endblock %}
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  <pre><code>from unicodedata import name
  from django.urls import path
  from . import views
  app_name = 'blog'
  urlpatterns = [
  path(&quot;&quot;, views.PostListView.as_view(), name=&quot;list&quot;),
  path(&quot;&lt;slug:slug&gt;/&quot;, views.PostDetailView.as_view(), name=&quot;detail&quot;),
  path(&quot;&lt;slug:slug&gt;/add-comment&quot;, views.CommentView.as_view(), name=&quot;commentview&quot;)
  ]
  </code></pre>
  <p><strong>models.py</strong></p>
  <pre><code>from django.contrib.auth.models import User
  from django.db import models
  from django.urls import reverse
  
  class Post(models.Model):
      title = models.CharField(max_length=255)
      slug = models.SlugField(max_length=255, unique=True)
      author = models.ForeignKey(User, on_delete=models.CASCADE)
      body = models.TextField()
      created = models.DateTimeField(auto_now_add=True)
      updated = models.DateTimeField(auto_now=True)
  
  def __str__(self):
      return self.title
  
  def get_absolute_url(self):
      return reverse ('blog:detail', kwargs={&quot;slug&quot;:self.slug})
  
  class Meta:
      ordering = (&quot;-created&quot;,)
  
  class Comment(models.Model):
      post = models.ForeignKey(Post, related_name=&quot;comments&quot;, on_delete=models.CASCADE)
      name = models.CharField(max_length=255)
      body = models.TextField()
      date = models.DateField(auto_now_add=True)
      slug = Post.slug
  
  def __str__(self):
      return reverse (self.post.title, self.name, self.post.slug)
  </code></pre>
  <p><strong>views.py</strong></p>
  <pre><code>from xml.etree.ElementTree import Comment
  from django.views.generic import DetailView, ListView, CreateView
  from .models import Post, Comment
  
  class PostListView(ListView):
      model = Post 
  
  class PostDetailView(DetailView):
      model = Post
  
  class CommentView(CreateView):
      model = Comment
      template_name = 'add_comment.html'
      fields = '__all__'
  </code></pre>