【问题标题】:Import css in Django在 Django 中导入 css
【发布时间】:2017-01-16 15:47:06
【问题描述】:

我使用 django1.10

我参考官方文档 https://docs.djangoproject.com/en/1.10/intro/tutorial06/

我的项目名称:我的站点

结构:

  • 我的网站-

         - mysite - urls.py
    
                   -views.py
    
                    ...
    
         - templates - index.html 
    
                     - images 
         - static - mysite - assets - css - main.css
    
                                    - js
    
                                    ...
    

    在我的 index.html 中

添加

{% load staticfiles % } <link rel="stylesheet" text = 'html/css' href="{% static 'mysite/static/main.css' %}" />

它说我有一个关于 TemplateSyntaxError 的无效块标签 &lt;link rel="stylesheet" type = 'text/css' href="{% static 'mysite/static/assets/css/main.css' %}" /&gt;

views.py(关于静态文件部分) STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), '/mysite/static/', ] STATIC_URL = '/static/' STATIC_ROOT='/mysite/static/'

我应该注意什么?

【问题讨论】:

    标签: html django css django-templates


    【解决方案1】:

    你好,亲爱的,试着让 python manage.py collectstatic... 希望能解决你的问题?

    【讨论】:

    • You have requested to collect static files at the destination location as specified in your settings. This will overwrite existing files! Are you sure you want to do this? 这个消息正常吗?我该如何选择?
    • 是的,如果您在生产服务器上工作,或者您应该在设置中指定静态目录的当前位置 STATIC_ROOT="/mysite/static/"
    • 是的,该消息是正常的。每当您进行任何更改或将任何其他静态文件添加到您的项目时,您都应该这样做。这只是一个简单的检查,让您重新检查所有内容,因此 django 开发人员不会有很多人抱怨丢失的文件
    猜你喜欢
    • 2019-01-05
    • 2014-06-22
    • 2016-12-13
    • 2020-06-16
    • 1970-01-01
    • 2022-08-12
    • 2013-04-22
    • 2011-09-20
    相关资源
    最近更新 更多