0

I'm trying to load a template visit_form.html which is a DetailView with a form within it. Each time I click on a link from main.html the wrong template gets loaded -> main_detail.html. I have cleared browser cache, invalidated caches.

The goal is to have the MainVisitDisplay render the visit_form.html, but all I get is the main_detail.html. It throws an error for main_detail.html when I change the location of the main_detail.html template, and throws a "TemplateDoesNotExist" error, looking for the main_detail.html template.

My MWE is:

urls.py

from django.conf.urls import url
from . import views
from django.urls import path

urlpatterns = [
    path('', views.index, name='index'),
    path('main/', views.MainListView.as_view(), name='main'),
    path('main/<int:pk>/', views.MainDetailView.as_view(), name='main_detail'),
    path('visit/add/<int:pk>/', views.MainVisitDisplay.as_view(), name='visit_form'),
]

views.py

class MainVisitDisplay(DetailView):
    model = Main
    template = "visit_form.html"

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['form'] = VisitForm()
        return context


class MainDetailView(generic.DetailView):
    template_name = "clincher/main_detail.html"
    model = Main

main.html (template) url

{% url 'clincher:visit_form' main.id %}
Nicolas
  • 374
  • 4
  • 18

1 Answers1

0

This was a really simple. use template_name = "template_name.html" NOT template = "template_name.html. Not sure why it kept rendering the other templates. Also, apparently, Django 2.0 does not cache templates, but feel free to confirm or deny this.

Nicolas
  • 374
  • 4
  • 18