setting up Django Compressor

394 views
Skip to first unread message

Phil

unread,
Aug 31, 2012, 11:17:57 AM8/31/12
to django...@googlegroups.com
Hi,

Django1.4, Python2.7

I am currently trying to get django compressor to work locally, I installed django_compressor via pip install earlier, added it to my installed apps. Here is a copy of my base template....

************************
{% load i18n %}
{% load compress %}
<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8" lang="en"> <![endif]-->
<!--[if IE 9 ]>   <html class="ie9"  > <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html> <!--<![endif]-->
    <head>
        <meta charset="utf-8"/>
               
        {% compress css %}
        <link rel="stylesheet" media="all" href="{{ STATIC_URL }}css/style.css" type="text/css" charset="utf-8" />
        {% endcompress %}
        .....
************************


When I view the source it outputs the following....

**************************
<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8" lang="en"> <![endif]-->
<!--[if IE 9 ]>   <html class="ie9"  > <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html> <!--<![endif]-->
	<head>
		<meta charset="utf-8"/>

		<link rel="stylesheet" href="/media/CACHE/css/fbe3d01c9f33.css" type="text/css" media="all" />

**************************


So it is creating the cached css file, but it doesn't seem to be able to find it(ie page loads with no style applied to it), any ideas what it could be that I am missing?


Joni Bekenstein

unread,
Sep 1, 2012, 10:09:41 AM9/1/12
to django...@googlegroups.com
The generated css file seems to be in your media directory. If you copy that URL, can you see the css file? Are you using Django's dev server (runserver)? If so, did you add to your urls.py a view to serve the media files? (and that view should only exist when DEBUG is true since in production you're probably going to serve static files and media files directly with your webserver)

Phil

unread,
Sep 2, 2012, 10:13:52 AM9/2/12
to django...@googlegroups.com
Hi Joni,

Thanks a million for reply.

Yes I am using django runserver, its a working site just trying to get compressor working locally before moving to production. My css works fine without the compressor app. I can't see the file if I copy it in my url I get a 500 error and the "CACHE" folder doesn't seem to exist anywhere. I didn't have anything in my "urls.py" for media, but I added the following to see if it would help but it still didn't work...

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

Joni Bekenstein

unread,
Sep 2, 2012, 10:38:27 AM9/2/12
to django...@googlegroups.com
Just to cover the basics, did you follow all installation steps described here:

Mainly adding 'compressor.finders.CompressorFinder' to STATICFILES_FINDERS


Another thing kind of odd is that your css URL starts with /media/. Whats your STATIC_URL and MEDIA_URL setting? Check this out: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_URL

It looks like its defaulting to MEDIA_URL, but you said you were using Django 1.4, which should have STATIC_URL available.

Phil

unread,
Sep 5, 2012, 1:29:21 PM9/5/12
to django...@googlegroups.com
Hi Joni,

Yes I have 'compressor.finders.CompressorFinder' added. All the requirements are installed too I double checked them all, tried installing them all individually and it said they were all installed already. When I first setup the site it was using django1.3, but recently upgraded it.

My static url setting is....

STATIC_URL = '/media/'

and media is(for local setup)...

MEDIA_URL = 'http://127.0.0.1:8080/media/'

Not sure what's going on, might just try another compressor at this stage as I am not having any joy with this one.
Reply all
Reply to author
Forward
0 new messages