Django: how do you serve media / stylesheets and link to them within templates

后端 未结 7 1672
心在旅途
心在旅途 2020-12-07 09:47

Variations of this question have been asked, but I\'m still unable to get my stylesheets to load correctly when my templates are rendered.

I\'m attempting to serve s

相关标签:
7条回答
  • 2020-12-07 10:14

    Just thought I'd chime in quickly. While all the propositions here work just fine, and I do use Ty's example while developing, once you hit production you might want to opt to serve files via a straight Apache, or whichever else server you're using.

    What I do is I setup a subdomain once I'm done developing, and replace all links to static media. For instance:

    <link rel="stylesheet" type="text/css" href="http://static.mydomain.com/css/style.css" />
    

    The reasons for doing this are two-fold. First, it just seems like it would be slower to have Django handle these requests when it's not needed. Second, since most browsers can actually download files simultaneously from 3 different domains, using a second sub-domain for your static files will actually speed up the download speed of your users.

    0 讨论(0)
提交回复
热议问题