views:

45

answers:

1

In the development environment, static files are served properly as long as the url pattern is limited to one directory. Sub directories lose the css. For example the css processes for the template attached to the following url:

//localhost:8000/create/

however this:

//localhost:8000/edit/2/

will not provide the css even if it's the same template.

the url.py code is as follows:

site_media = os.path.join( 
  os.path.dirname(__file__), 'site_media'
)

and

(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', 
{ 'document_root': site_media }),

the view code is:

def edit_record(request, id):
        if request.method == 'POST':
                a=ProjectRecord.objects.get(pk=id)
                form = RecordForm(request.POST, instance=a)
                if form.is_valid():
                        form.save()
                        return HttpResponseRedirect('/')
        else:
                a=ProjectRecord.objects.get(pk=id)
                form = RecordForm(instance=a)
        return render_to_response('productionModulewire.html', {'form': form})

am I missing something?

A: 

All I can think of here is that your template is using relative paths to include the CSS.

check your <link rel="stylesheet" and make sure they begin with a / (or are a full URL)

Mez
thank you. changed "../site_media" to "/../site_media" and problem disappeared.
kjarsenal
I think that `"/../site_media"` in a URL translates (or should translate) to `"/site_media"`, true? Otherwise the server is extremely vulnerable to all sorts of "over the top and into the password file" types of attacks.
Peter Rowell
indeed, you should probably just use /site_media
Mez