1

I have created a book application - each book contains several sections and each section contains several sub-sections.

The app works fine and each sub-section "shows" its content on the right page etc.. Problem is that I want that each sub-section will have a different html/css/js code & effects.

Here is some of the URLS.PY code:

 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'),

)

Some of the views.py code:

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)

As you can see, each sub section's page is determined by the slug. Of course that each one of them will have the SAME template and that is my problem. I want to make different css/js effects for each page.

1
  • 'info/ssection_disp.html' and 'section_display.html' are different pages rigth? If they are you don't have to use same css/js for the pages. You can use different css/js in different pages. Commented Feb 5, 2013 at 11:15

1 Answer 1

2

Create 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 %}

Follow this pattern in other pages and you can now use different css/js as you want

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.