我正在尝试链接html中的一些CSS (运行Django服务器),问题是如果在Windows上运行并使用\(反斜杠),那么它就不能在Linux上正确执行(因为它使用/(斜杠))
基于当前正在执行的操作系统,修改我的base.html中的路径的最佳方法是什么?
例如,如果是Windows,则应该是:
<link rel="stylesheet" href="{% static "\style.css" %}"/>
^但是在Linux上:
<link rel="stylesheet" href="{% static "/style.css" %}"/>
^发布于 2015-07-22 09:21:02
首先,在您的STATIC_ROOT中配置STATIC_URL和settings.py
import os
# Project root is intended to be used when building paths,
# e.g. ``os.path.join(PROJECT_ROOT, 'relative/path')``.
PROJECT_ROOT = os.path.abspath(os.path.dirname(__name__))
# Absolute path to the directory where ``collectstatic``
# will collect static files for deployment.
#
# For more information on ``STATIC_ROOT``, visit
# https://docs.djangoproject.com/en/1.8/ref/settings/#static-root
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static/')
# URL to use when referring to static files.
#
# For more information on ``STATIC_URL``, visit
# https://docs.djangoproject.com/en/1.8/ref/settings/#static-url
STATIC_URL = '/static/'那么你应该可以使用
{% static 'project/css/style.css' %}据我所知,这将考虑到兼容性。
考虑阅读有关管理静态文件的内容。
https://stackoverflow.com/questions/31558418
复制相似问题