1

I'm deploying a Django application that is based on a whole lot of static content. All of the computers using the application are on an intranet, with the static content available through nfs.

Can django be configured to let users get the static data through their nfs mounts, rather than forcing it all through a web server?

If I've got this in a template:

<img src="/path/to/img.png"/>

The browser is requesting that image from

http://localhost:8000/path/to/img.png

What I'm trying to do is get the client to treat that as a local path, rather than asking a server for it.

ajwood
  • 18,227
  • 15
  • 61
  • 104

2 Answers2

5

To reference a file in your file system (NFS mounted or otherwise), the URI to use is file:///path/to/file. However, that will not work in your case -- <a href="file:///path"> will only work from a static HTML file loaded from the local filesystem.

For security reasons, a web page is not allowed to access the local filesystem. See Why can't I do <img src="C:/localfile.jpg">?

If you want to speed up access to static files, one option would be to set up a separate light-weight webserver that's dedicated to service your static files (perhaps nginx? or lighttpd? or mongoose?) and use the URL of that server as your MEDIA_URL.

Community
  • 1
  • 1
Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
0

Well, you should try it out. If django is treating the static content path as just another constant, then your network share path should work just well. But, if it isn't, then you can try defining your own constant like: static_on_network_share or something and use that constant while loading content in templates/html.

Prasanth
  • 5,230
  • 2
  • 29
  • 61