arashiyama
arashiyama

Reputation: 97

Call to django view returning results from another view

I have two views, defined as follows:

class ListResultView(LoginRequiredMixin, ListView):
    model = Result

class GalleryView(LoginRequiredMixin, ListView):
    model = Result
    template = 'gallery.html'
    context_object_name = 'gallery'

So ListResultView() uses the implicit defined result_list.html as a template and result is impliciyly defined as the context model, whereas GalleryView (which is a prettier list of the same data) uses the explicitly defined template 'gallery.html' and the context object is defined as 'gallery'.

I call them using the following urls.py (which is the main urls.py, not an included one):

from django.conf.urls import patterns, include, url
import lc.views
from django.views.generic import TemplateView
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', TemplateView.as_view(template_name="about.html"), 
        name='indexpage'), 
    url(r'^gallery/$', lc.views.GalleryView.as_view(), name='gallery'),
    url(r'^admin/', include(admin.site.urls), name='admin'),  
    url(r'^listquery/', lc.views.ListCView.as_view(),
        name='s_queries',),
    url(r'^listresult/', lc.views.ListResultView.as_view(),
        name='s_results',),
    url(r'^new/', lc.views.CreateCQuery.as_view(),
        name='query_new',),    
    url(r'^login/$', 'django.contrib.auth.views.login', name='login'),
    url(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/login'},              name='logout'),
    url(r'^deletes/(?P<pk>\d+)/$', lc.views.DeleteS.as_view(), name='delete_s'),
    url(r'^deleter/(?P<pk>\d+)/$', lc.views.DeleteResult.as_view(), name='delete_result'),
    url(r'^resultview/(?P<pk>\d+)/$', lc.views.ResultDetailView.as_view(),
        name='resultview'),
    url(r'^notyet', TemplateView.as_view(template_name="not_impl.html"), name="notyet",),
)

The problem that is hitting me is that when I call the GalleryView url, I am getting the ListResultView response. I can't see any error messages, and wonder if anyone can point me at either where I am going wrong, or how to debug it. My current thought is to throw away class based views and rewrite as function based views, just so I can get a firmer handle on what is going on, however due to time pressures I'd rather not do that.

Upvotes: 0

Views: 1021

Answers (1)

cor
cor

Reputation: 3393

Change template by template_name at your GalleryView.

Upvotes: 1

Related Questions