所以我有一個 javascript 檔案,我試圖鏈接到我的 html 檔案。我已經設法將 css 檔案連接到多個 html 檔案,所以我的靜態設定似乎運行良好,但是我收到一條錯誤訊息:“未找到:/item-store.js”(item-store.js 是我的JavaScript 檔案)。(順便說一句:我的 html 檔案名為“item-store.html”)我不知道如何解決這個問題。有什么想法嗎?
這是我的 html 檔案:
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
...Code...
</head>
<body>
...Code...
<script src="item-store.js"></script>
</body>
</html>
我的 settings.py 檔案的幾行:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app'
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR/'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "templates"),
)
MEDIA_ROOT = ''
MEDIA_URL = ''
我今天會偶爾活躍一下,所以如果需要,我可以澄清任何事情或提供更多資訊。感謝您的時間!
uj5u.com熱心網友回復:
這是模式:
模板.html
<srcipt src="{% static 'folder/script.js' %}"></script>
設定.py
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'staticfiles')
]
專案結構:
project
|- app1
|- app2
|- ...
|- project
|- staticfiles
|- folder
|- script.js
|- templates
|- manage.py
|- ...
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/494786.html
