views:

47

answers:

2

I am using Django-page-CMS

Everything works fine However once I create my own views which extend from pages used within the CMS the CSS does not display.

This is strange because these pages display the CSS fine, as long as I do not use my own views.

I would greatly appreciate some help on this matter or at least some suggestions on why this is happening and how it could be rectified.

I am using the static files trick.

if settings.DEBUG:
urlpatterns += patterns('',
    url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
    url(r'^admin_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.ADMIN_MEDIA_ROOT}),

Here is how I have linked styles....links to jquery also exist but this should not affect.

<head>
<link type="text/css" rel="stylesheet" href="{{ MEDIA_URL }}css/style.css" />
</head>

I have some styles in pages which extend the base linked in the following way....

{% extends "base.html" %}
{% block page_style %}
<link type="text/css" rel="stylesheet" href="{{ MEDIA_URL }}css/index.css" />
{% endblock %}

Again, Everything works fine until I create my own views and pages which extend from any of these pages. Once I view the new pages no css displays in any page. not even the base however if I do not use my own views everything is displayed fine. I would greatly appreciate help on this matter.

A: 

Your {% block page_style %}{% endblock %} should be within of base.html

So base.html:

<html>
    <head>
        {% block extrahead %}{% endblock %}
    </head>
    <body></body>
</html>

yourtemplate.html:

{% extends "base.html" %}
{% block extrahead %}
<link type="text/css" rel="stylesheet" href="{{ MEDIA_URL }}css/index.css" />
{% endblock %}
msamoylov
Nope unfortunately it makes no difference. Do you have any idea why this is happening?
Rick
The base actually stops working when it is placed within {% block page_style %} this cannot be right.
Rick
A: 

The MEDIA_URL was not coming through properly.

RequestContext() was the problem. The content_instance was not set therefore the MEDIA_URL variable would not come through when the template was rendered.

When using render_to_response.....

return render_to_response(YOUR_TEMPLATE, YOUR_TEMPLATE_CONTEXT,
context_instance=RequestContext(request))
Rick