简体   繁体   English

Django STATIC_FILE无法按照我的想法工作?

[英]Django STATIC_FILE doesn't work as i thought?

I've searched for answer for this question, but i havent found any solution for my problem. 我一直在寻找这个问题的答案,但是我没有找到解决我问题的方法。 I want to link css to my project, but just cant handle how STATIC_URL work 我想将CSS链接到我的项目,但无法处理STATIC_URL的工作方式

  <head>
    {% load static from staticfiles %}
    <link rel="stylesheet" type="text/css" href="{% static "css/style.css" %}">
  </head>

it's to much code to post here so here are the links: settings.py: http://pastebin.com/9Bsg3u1h 要在此处发布大量代码,因此此处是链接:settings.py: http : //pastebin.com/9Bsg3u1h

And I render with context_instance=RequestContext(request) parameter of course. 我当然使用context_instance=RequestContext(request)参数进行渲染。 I got files structure like this: 我得到了这样的文件结构:

Django_project
 ...
 appname
 templates
 static 

I tried also to place static directory in many project, in appname, and even in templates. 我还尝试将静态目录放置在许多项目,appname甚至模板中。 Can someone explain me how should it look for my project? 有人可以解释一下我该如何寻找我的项目吗?

Use the builtin static , not static from staticfiles : 使用内置的static ,而不是staticfiles static

  <head>
    {% load static %}
    <link rel="stylesheet" type="text/css" href="{% static "css/style.css" %}">
  </head>

https://docs.djangoproject.com/en/dev/ref/templates/builtins/#static https://docs.djangoproject.com/zh-CN/dev/ref/templates/builtins/#static

Django ships with a static template tag. Django附带了一个static模板标签。 You can use this regardless if you're using RequestContext or not. 无论是否使用RequestContext都可以使用它。

Note 注意

The staticfiles contrib app also ships with a static template tag which uses staticfiles' STATICFILES_STORAGE to build the URL of the given path. staticfiles contrib应用程序还附带一个static模板标签,该标签使用staticfiles的STATICFILES_STORAGE来构建给定路径的URL。 Use that instead if you have an advanced use case such as using a cloud service to serve static files... 如果您有高级用例(例如使用云服务来提供静态文件),请改用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM