How to load data from local static path in templates (security error)

34 views
Skip to first unread message

Adam Zedan

unread,
Aug 17, 2011, 2:00:13 PM8/17/11
to django...@googlegroups.com
Hi it seems I cant access data from local static paths such as c:\\somefolder\somefile.gif in my templates when I enter the url
the code for my template is simplified to something like this

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>Demo</title>
    </head>
    <body>
        <img src="file:///c:/bender.gif" />
    </body>
</html>

The title change to Demo. which shows that the page has loaded but
I get the error in firefox saying:
Security Error: Content at http://127.0.0.1:8000/db/ may not load or link to file:///c://bender.gif

Daniel Roseman

unread,
Aug 17, 2011, 3:39:00 PM8/17/11
to django...@googlegroups.com
No, you can't do that. Why would you want to? Your users aren't going to have that file on their machines, so what's the point of referencing a local file path?

You serve the content through your webserver, with an http:// protocol. In development, you can do this through Django's development server:
--
DR. 

Tom Evans

unread,
Aug 18, 2011, 4:43:29 AM8/18/11
to django...@googlegroups.com

The OP clearly doesn't understand why though, see his other thread on
this topic.

Your browser is a careful beast. It won't allow a webpage loaded from
the internet zone to load things from the local zone, as That Would Be
Bad. When you 'double click' the file and 'it works', what is actually
happening is that the webpage is loaded from the local zone, and so
access is allowed.

Also, Django is a web app. This means that most users who use your
site will not be using it from your desktop, so they would not be able
to access files on your local machine. Therefore, you need to provide
a way to serve these files over HTTP, so that other users can access
them. See the link in Daniel's reply on how to do this.

Cheers

Tom

Reply all
Reply to author
Forward
0 new messages