peterbe / django-static

Template tags for better serving static files from templates in Django
BSD 2-Clause "Simplified" License
193 stars 28 forks source link

local variable 'new_file_content' referenced before assignment #2

Closed saturdayplace closed 14 years ago

saturdayplace commented 14 years ago

I keep getting this error. It feels like a configuration error, but I'm not sure what I've mis-configured. Here's my setup:

OS: Win7

Relevant settings.py settings:

MEDIA_URL = "/media/"
DJANGO_STATIC = True
DJANGO_STATIC_SAVE_PREFIX = "B:/django projects/myproject/media/cache"

The template markup where I'm using django_static:

<link rel="stylesheet" href="{{ MEDIA_URL }}{% slimfile 'css/base.css' %}" />

Going to a page will give the above error. Refreshing the page will clear the error, and show a request for /media/css/base.TIMESTAMP.css that is a 404. I get the same cycle again if I restart the webserver and refresh the page.

Here's the output from the traceback:

TemplateSyntaxError at /myPage/

Caught UnboundLocalError while rendering: local variable 'new_file_content' referenced before assignment

The error show up on line 506 of django_static\templatetags\django_static.py in _static_file

Local Vars: DEBUG True DJANGO_STATIC_NAME_PREFIX '' DJANGO_STATIC_SAVE_PREFIX 'B:/django projects/myproject/media/cache' MEDIA_URL None PREFIX 'B:/django projects/myproject/media/cache' apart ('img/bg-top', '.png') fileinfo ('img/bg-top.1267205927.png', 1267205927L) filename 'img/bg-top.png' filepath 'B:\django projects\myproject\media\img/bg-top.png' is_combined_files False m_time None map_key 'img/bg-top.png' new_filename 'img/bg-top.1267205927.png' new_filepath 'B:/django projects/myproject/media/cache\img bg-top.1267205927.png' new_m_time 1267205927L old_new_filename None optimize_if_possible False symlink_if_possible False warn_no_file True wrap_up <function wrap_up at 0x0273A2B0>

Some CSS that looks relevant to the local_vars

# in /media/css/base.css
html {
    background: url('img/bg-top.png') no-repeat center top;
}
peterbe commented 14 years ago

Thanks. I'll try to write a test to reproduce it.

peterbe commented 14 years ago

Do you know if you have slimmer installed? You can test by running python and simply...

import slimmer

peterbe commented 14 years ago

I've managed to reproduce this and working on a fix. As a quick remedy if you want you can just install slimmer or set up the YUI Compressor.

peterbe commented 14 years ago

Fixed now. Version 1.3.4.

The problem happened because you had windows and no whitespace optimization enabled. Thanks for reporting!