title: How to create a view for details of a single post and url in django?
body: <p>I am creating a website with a blog application in django 2.2. I only have a problem with the last step, which is to create a view for a single post. Unfortunately, I don't know how to finish it.</p>
  
  <p>I created the simplest view I can, but after entering it, I get a 500 error from the server.</p>
  
  <pre class="lang-py prettyprint-override"><code> def single_post(request):
       return render(request=request, template_name="posts/single_post.html")
  </code></pre>
  
  <p>This is my model, view and url:</p>
  
  <p>models.py</p>
  
  <pre><code># Post models
  from django.db import models
  from datetime import datetime
  from django.utils.text import slugify
  
  class Post(models.Model):
      title = models.CharField(max_length=150, verbose_name="Tytuł")
      content = models.TextField(verbose_name="Zawartość")
      lead = models.CharField(max_length=35, verbose_name="Skrót artykułu")
      published = models.DateTimeField(verbose_name="Data publikacji", default=datetime.now())
      slug = models.SlugField(unique=True)
      cover = models.ImageField(upload_to='images/')
  
      def save(self, *args, **kwargs):
          self.slug = slugify(self.title)
          super(Post, self).save(*args, **kwargs)
  
      def __str__(self):
          return self.title
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code>from django.contrib import admin
  from django.urls import path, include
  from . import views
  
  app_name = "posts"
  
  urlpatterns = [
      path("posts/", views.posts_list, name="posts_list"),
      path('&lt;str:slug&gt;/', views.single_post, name='single_post'),]
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from django.shortcuts import render
  from django.http import HttpResponse
  from .models import Post
  
  # Create your views here.
  
  def posts_list(request):
      return render(request=request, template_name="posts/posts_list.html", context={"posts": Post.objects.all})
  
  def single_post(request,slug):
      post = Post.objects.get(slug=slug)
      return render(request=request, template_name="posts/single_post.html", context={"post": post})
  </code></pre>
  
  <p>templates/posts/posts_list.html - is a page with all posts at exmaple.com/posts/</p>
  
  <pre><code>&lt;section class="bg-light py-5" id="aktualnosci"&gt;
  &lt;div class="container"&gt;
      &lt;h1&gt;Informacje o zmianach w prawie podatkowym&lt;/h1&gt;
      &lt;div class="divider"&gt;&lt;/div&gt;
      &lt;p class="text-paragraph pt-3"&gt;Lorem ipsum dolor sit amet consectetur adipisicing elit. Ullam iure consectetur accusantium delectus, iusto culpa mollitia eum molestiae at? Ab!&lt;/p&gt;
      &lt;div class="row py-3"&gt;
          {% for post in posts %}
          &lt;div class="col-lg-6"&gt;
              &lt;div class="news-card mb-3"&gt;
                  &lt;div class="text-center text-white bg-blue d-flex align-items-center news-card-date"&gt;
                      &lt;div class="mx-auto news-card-date-body w-75"&gt;
                          &lt;i class="far fa-calendar-alt d-none d-block mx-auto"&gt;&lt;/i&gt;
                          &lt;span class="d-block news-card-date-value mt-1"&gt;{{ post.published }}&lt;/span&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="news-card-body"&gt;
                      &lt;div class="news-card-img"&gt;
              &lt;img class="img-fluid" src="{% static 'main/images/126.jpg' %}" alt=""&gt;
                      &lt;/div&gt;
                      &lt;div class="news-card-content"&gt;
                          &lt;div class="news-card-content-inner"&gt;
                              &lt;h2&gt;{{ post.title }}&lt;/h2&gt;
                              &lt;p class="text-paragraph"&gt;{{ post.lead }}&lt;/p&gt;
                              &lt;a class="pb-2" href="{{ post.slug }}"&gt;Czytaj więcej&lt;/a&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          {% endfor %}
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>I would like visitors to the site to be able to read the entire article. Currently, I was able to create only the entire page with all posts and their shortcuts.</p>