开发者

views created in django-page-CMS disables all CSS? code included, a fix please

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 i开发者_如何学Cn 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.


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


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))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜