我有兩個視圖,其定義如下:電話DJANGO視圖從另一視圖返回結果
class ListResultView(LoginRequiredMixin, ListView):
model = Result
class GalleryView(LoginRequiredMixin, ListView):
model = Result
template = 'gallery.html'
context_object_name = 'gallery'
所以ListResultView()使用隱式定義的result_list.html作爲模板和結果impliciyly定義爲上下文模型,而GalleryView(它是相同數據的更漂亮的列表)使用明確定義的模板'gallery.html',上下文對象被定義爲'畫廊'。
我打電話給他們使用以下urls.py(這是主要的urls.py,而不是包括一個):
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",),
)
是打我的問題是,當我叫URL圖庫視圖,我得到ListResultView響應。我看不到任何錯誤消息,並懷疑是否有人可以指出我要出錯的位置,或者如何調試它。我目前的想法是丟棄基於類的視圖並將其重寫爲基於函數的視圖,這樣我就可以更好地處理髮生的事情,但是由於時間壓力,我寧願不這樣做。
試試'url(r'^ gallery/$'' – pynovice
你可以顯示完整的urls.py嗎?是通過include加載的文件 - 如果是的話,你能顯示父文件嗎? –
沒有變化,謝謝認爲雖然! – arashiyama