2013-02-05 22 views
1

我已經創建了一本書應用程序 - 每本書包含幾個部分,每個部分包含幾個子部分。Django - 每頁不同的html/css/js代碼

該應用程序工作正常,每個子節「顯示」其內容在右頁等。 問題是我希望每個子節都會有不同的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) 

正如你可以看到,每個子部分的頁面由slu determined決定。 當然,他們每個人都會有相同的模板,這是我的問題。 我想爲每個頁面製作不同的CSS/JS效果。

+0

'info/ssection_disp.html'和'section_display.html'是不同的頁面?如果他們是你不必使用相同的CSS/JS的網頁。你可以在不同的頁面中使用不同的css/js。 –

回答

2

創建base.html文件

base.html文件

<html> 
    <head> 
     <title>{% block title %}{% endblock %}</title> 

     {% block css %}{% endblock %} 
     {% block js %}{% endblock %} 
    </head> 

    <body> 
     {% block content %}{% endblock %} 
    </body> 
</html> 

page1.html

{% extends "base.html" %} 

{% block title %}{{block.super}}"title here"{% endblock %} 

{% block css %}{{block.super}} 
    "css here" 
{% endblock %} 

{% block js %}{{block.super}} 
    "js here" 
{% endblock %} 

{% block content %} 
    content here 
{% endblock %} 

按照其他頁面這種模式,你現在可以使用不同的CSS/js如你所願

相關問題