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 %}