title: Django Error: TemplateDoesNotExist at /trade/confirm/
body: <p>When a user clicks a button in a form, I am sending a POST request in a form with <code>action=&quot;{% url 'trade-confirm' %}&quot;</code>. The method that is called, <code>insert_transaction</code>, is working correctly. But when that method is finished it goes to <code>confirmed-trade/&lt;int:pk&gt;/</code>, which is showing the below error:</p>
  <p><code>TemplateDoesNotExist at /trade/confirm/</code></p>
  <p><code>confirmed-trade/20/</code></p>
  <p>Screenshot of error here: <a href="https://i.stack.imgur.com/X3t5X.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p><strong>Below is my code:</strong></p>
  <p><strong>Folder structure:</strong> - <a href="https://i.stack.imgur.com/mzhxQ.png" rel="nofollow noreferrer">Folder structure screenshot</a></p>
  <pre><code>game-exchange
  -blog
  --migrations/
  --static/
  --templates/
  ---blog/
  ----about.html
  ----base.html
  ----matches.html
  ----transaction.html
  ----your-trades.html
  --admin.py
  --apps.py
  --models.py
  --urls.py
  --views.py
  -django_project/
  -media/
  -users/
  -manage.py
  -posts.json
  -Procfile
  </code></pre>
  <p><strong>blog/urls.py</strong></p>
  <pre><code>urlpatterns = [ #the 2 relevant url's
      path('confirmed-trade/&lt;int:pk&gt;/', views.TransactionDetailView.as_view(), name='confirmed-trade'), # Loads transaction form
      path('trade/confirm/', views.insert_transaction, name='trade-confirm'), # url to accept POST call from Your Trades page to create a Transaction
  ]
  </code></pre>
  <p><strong>blog/models.py (transaction object only)</strong></p>
  <pre><code>class Transaction(models.Model):
      name = models.TextField()
      created_date = models.DateTimeField(default=timezone.now)
      trade_one = models.ForeignKey(Trade, on_delete=models.CASCADE, related_name='trade_one', db_column='trade_one')
      trade_two = models.ForeignKey(Trade, on_delete=models.CASCADE, related_name='trade_two', db_column='trade_two')
          status = models.TextField(default='Waiting for 2nd confirmation') 
  
      def get_transaction_name(self):
          return ''.join([self.trade_one_id, ' and ', self.trade_two_id, ' on ', timezone.now().strftime(&quot;%b %d, %Y %H:%M:%S UTC&quot;), ')'])
  
      def save(self, *args, **kwargs):
          self.name = self.get_transaction_name()
          super(Transaction, self).save(*args, **kwargs)
  
      def __str__(self):
          return self.name 
  
      def get_absolute_url(self):
          return reverse('confirmed-trade', kwargs={'pk': self.pk})
  </code></pre>
  <p><strong>blog/views.py:</strong></p>
  <pre><code>def insert_transaction(request):
      if 'trade_1_id' not in request.POST or 'trade_2_id' not in request.POST:
          messages.add_message(request, DANGER, 'There was a problem confirming this trade. Please try again.')
          return redirect('/matches')
  
      trade_one_id = request.POST['trade_1_id']
      trade_two_id = request.POST['trade_2_id']
  
      transaction = Transaction(trade_one_id=trade_one_id, trade_two_id=trade_two_id)
      transaction.save()
      return render(request, 'confirmed-trade/' + str(transaction.id) + '/')
  
  class TransactionDetailView(DetailView):
      model = Transaction
  </code></pre>
  <p><strong>UPDATE: I did solve the issue for a short time, but the same error came back:</strong></p>
  <p>In addition to the answer below, I also had to update the TEMPLATES var in settings.py to be:</p>
  <pre><code>'DIRS': [os.path.join(BASE_DIR, 'templates')],
  </code></pre>
  <p><strong>This solved the issue for a short time, but I'm running into it again</strong>. The weird part is that if I manually go to the url <code>http://localhost:8001/confirmed-trade/50/</code>, it loads the template. But when the insert_transaction calls <code>return render(request, 'confirmed-trade/' + str(transaction.id) + '/')</code>, I get the error. Can someone please help me? I'm really stuck here</p>