現在、django にフォルダー構造が設定されています。
{アプリ名}\templates\
{アプリ名}\templates\assets\css\
<link rel="stylesheet" href="assets/css/bootstrap.css" />
しかし、テンプレートのようなものを に含めようとすると、{appname}\templates\
何らかの理由で読み込まれません。Twitter から直接読み込むこともできますが、可能であれば相対パスを保持したいと思います。
これがうまくいかないのはなぜですか?それが手がかりである場合、PyCharm のサブフォルダーは明るい灰色で表示されますが、なぜそれが起こっているのかもわかりません。
編集:わかりましたので、ここで静的ファイルを設定する方法を読みstatic
、メインプロジェクトフォルダーの下にディレクトリを設定し、css
その下にフォルダーを作成しました。
以下を含めるように 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.
)
そして追加しようとしました
<link rel="stylesheet" href="{{ STATIC_URL }}css/bootstrap.css" />
私のhtmlファイルに、しかしそれがロードされていません - ここで何が間違っていますか?