은 현재 장고에서 설정 한 폴더 구조를 가지고 장고에 상대 경로에서로드되지 :스타일 시트
\ 자산을 \ \가 {APPNAME} \ 템플릿 CSS를 \
{APPNAME} \ 템플릿
하지만 내 템플릿에 <link rel="stylesheet" href="assets/css/bootstrap.css" />
과 같은 내용을 넣으려고하면 {appname}\templates\
에로드됩니다. 어떤 이유로 든로드되지 않습니다. 트위터에서 직접로드 할 수 있지만 가능하면 상대 경로를 유지하는 것이 좋습니다.
왜이 기능이 작동하지 않을 수 있습니까? 그것이 어떤 실마리가 있다면 PyCharm의 하위 폴더가 밝은 회색으로 나타나며 그 이유가 확실하지 않습니다.
편집 : 좋아 그래서 정적 파일을 설정하는 방법에 here을 읽고, 그 아래에 css
폴더, 내 주요 프로젝트 폴더 아래에 static
디렉토리를 설정했습니다.
나는 업데이트 settings.py가 포함 : 다음
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
import os.path
STATICFILES_DIRS = (
os.path.dirname(__file__).replace('\\','/'),
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
와 나의 HTML 파일에
<link rel="stylesheet" href="{{ STATIC_URL }}css/bootstrap.css" />
를 추가하려고 시도하지만,로드 아니에요 - 내가 잘못 여기서 뭐하는거야 ?
괜찮 았는데, 나는 그 링크마다 미디어 디렉토리를 설정했다. 어떻게 장고에이'.css' 파일을 가져야합니까? – fox
거기에 들어가야 할 정적 디렉토리도 추가했습니다. – fox
(업데이트 된 원래 게시물) – fox