我创建了一个图书应用程序 - 每本书包含几个部分,每个部分包含几个子部分。
该应用程序运行良好,每个子部分在正确的页面上“显示”其内容等。问题是我希望每个子部分都有不同的 html/css/js 代码和效果。
这是一些 URLS.PY 代码:
url(r'^admin/', include(admin.site.urls)),
(r'^$', direct_to_template, {'template': 'index.html'}),
(r'^book/$','book.views.BookAll'),
(r'^book/$','book.views.BookAll'),
(r'^book/(?P<slug>[-\w]+)/$','book.views.Ssection_specific'),
(r'^book/info/(?P<slug>[-\w]+)/$','book.views.Ssection_details'),
)
一些views.py代码:
def Ssection_specific(request, slug): #display according to specified section object.
try:
section = Section.objects.get(slug=slug)
except Section.DoesNotExist:
raise Http404
ssection = SSection.objects.filter(section = section).order_by('subject')
context = {'ssection' : ssection,'section' : section}
return render_to_response('section_display.html', context, context_instance = RequestContext(request))# creates
def Ssection_details(request, slug):
try:
ssection = SSection.objects.get(slug = slug)
except SSection.DoesNotExist:
raise Http404
context = {'ssection' : ssection}
return render_to_response('info/ssection_disp.html', context, context_in)
如您所见,每个子部分的页面由 slug 确定。当然,他们每个人都有相同的模板,这是我的问题。我想为每个页面制作不同的 css/js 效果。