Where to place dependent Django template files?

My Django templates use a lot of related things: images, style sheets, etc.

Where should I put this file or how should I refer to them in the template itself?

While I use the development server.

I know that this is really an ordinary thing, but I cannot understand it.

+4
source share
3 answers

I put them in a folder called static , which is in the top-level folder of the web project.

Example:

/ static / IMG /
/ Static / JS /
/ Static / CSS /
/ Templates / Network urls.py
settings.py

In my urls.py file, I have the following rule:

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

My settings.py contains:

 MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'static').replace('\\', '/') ADMIN_MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'static/admin').replace('\\', '/') 
+5
source

We put ours under / media. Everything that is specifically related to the location of sites is further divided. Of course, none of these static materials is served by Django on the production site. They are often not even on the same physical server.

 /media /images - this is for content-specific images /video - these next 2 are normally symlinks to a /big_content folder ... /audio - so that they aren't included in our mercurial repository. /layout - everything that is tied to the basic templates. /css /js /images 
0
source

All Articles