I know this is something dumb, but I'm a new programmer and I've been smacking my head against it for 2 hours and you will likely see it in 2 seconds so... View AllEncountersListView which has declared template_name = 'encounter_list_all.html' is using instead 'encounter_list.html'. I know the view is being called since it prints to terminal as expected. Thanks for your time.
views.py:
class AllEncountersListView(generic.ListView):
model = Encounter
paginate_by = 20
template_name = 'encounters_list_all.html'
def get_queryset(self):
print('in allEncounterListView') #to prove the correct view is being called
return Encounter.objects.filter(user=self.request.user).order_by('-encounter_date')
urls.py:
urlpatterns = [
path('',views.index, name='index'),
path('openencounter/', views.open_encounter, name='openencounter'),
path('myencounters/', views.EncountersByUserListView.as_view(), name='my-encounters'),
path('allencounters/', views.AllEncountersListView.as_view(), name='all-encounters'),
path('encounter/<int:pk>', views.EncounterDetailView.as_view(), name = 'encounter-detail'),
path('todaysencounters/', views.TodaysEncountersListView.as_view(), name='todays-encounters'),
path('logout/', views.logout_view, name='logout'),
path('export/', views.export_data_view, name = 'export'),
]
file tree:
── Aents4
│ ├── __init__.py
│ ├── __pycache__
│ ├── asgi.py
│ ├── settings.py
│ ├── templates
│ │ ├── registration
│ │ │ └── login.html
│ │ └── temp
│ ├── urls.py
│ └── wsgi.py
├── db.sqlite3
├── encounters
│ ├── __init__.py
│ ├── __pycache__
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── 0002_auto_20210926_1548.py
│ │ ├── 0003_alter_encounter_encounter_date.py
│ │ ├── 0004_auto_20210927_1704.py
│ │ ├── 0005_animal_max_daily.py
│ │ ├── 0006_auto_20210928_1157.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ ├── models.py
│ ├── registration
│ │ └── login.html
│ ├── static
│ │ └── styles.css
│ ├── templates
│ │ ├── base_generic.html
│ │ ├── encounters
│ │ │ ├── encounter_detail.html
│ │ │ ├── encounter_form.html
│ │ │ ├── encounter_list.html
│ │ │ ├── encounters_list_all.html
│ │ │ ├── encounter_update_form.html
│ │ │ └── encounters_list_by_user.html
│ │ ├── index.html
│ │ ├── openencounter.html
│ │ └── registration
│ │ └── login.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
└── manage.py
CodePudding user response:
class AllEncountersListView(generic.ListView):
model = Encounter
paginate_by = 20
template_name = "encounters/encounters_list_all.html"
def get_queryset(self):
return Encounter.objects.filter(user=self.request.user).order_by('-encounter_date')
Try this please if you didn't already. Usually, when we are configuring our settings.py
, we make it look in the templates
directory for files, but you have subdirectory encounters
which contain the template files. Try to target that subdirectory with this line:
template_name = "encounters/encounters_list_all.html"
I hope this helps; please inform us about result so we can try other solutions if needed.
Maybe it didn't throw any errors because the Django class views has that functionality such that when template name is not specified it looks at the class name and tries to figure out which template to render; maybe that is why that other template is being used. Check the Django documentation for more information.