Django - referencing static files in templates

后端 未结 3 1243
深忆病人
深忆病人 2020-12-17 18:05

I\'m having difficulty referencing static files in my templates. I am using Twitter Bootstrap and have the bootstrap files (css, img, js) sitting at mysite/static.

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 18:55

    Are you setting the user_stylesheet context variable in your view? You need to set that before you can pass it onto templates.

    I usually just use the {{ static_url }} tag for doing this stuff, so my code for including bootstrap components would be like.

    
    
    

    Assuming that bootstrap folder is present inside static.

    EDIT

    For your case, to set user_stylesheet context variable, you'll need to do something like

    dict["user_stylesheet"]= 
    #add other context variables you might have to
    render_to_response(, dict, context_instance=RequestContext(request))
    

提交回复
热议问题