【发布时间】:2019-01-12 03:32:01
【问题描述】:
我已阅读有关此问题的所有类似问题,但仍然找不到答案。我从 HTML5 下载了一个模板以及所有必需的 CSS、JS 和图像,但是当我运行服务器时,我得到了:
**
Not Found: /erthreal/assets/js/main.js
[04/Aug/2018 12:02:40] "GET /erthreal/assets/js/main.js HTTP/1.1" 404 2126
[04/Aug/2018 12:02:40] "GET /erthreal/images/gallery/thumbs/06.jpg HTTP/1.1" 404 2159
[04/Aug/2018 12:02:40] "GET /erthreal/images/gallery/thumbs/07.jpg HTTP/1.1" 404 2159
**
我的 settings.py 文件中有以下内容:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'erthreal/erthreal/templates/'
],
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static/',),
'erthreal/static/erthreal',
]
在我的 index.html 中:
{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>personal</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="{% static "erthreal/assets/css/main.css" %}"/>
<noscript><link rel="stylesheet" href="erthreal/assets/css/noscript.css" /></noscript>
</head>
我很确定问题出在我的 view.py 中:
from django.shortcuts import render, HttpResponse
def index(request):
index = Index.objects.all()
return render(request, 'erthreal/templates/index.html')
我已经阅读了 django 网站和 howto 文件夹(它们几乎是彼此的副本)上的所有文档,但找不到关于如何修复它的答案。这是我的文件夹布局:
erthreal/
static/
erthreal/
assets/
CSS/
fonts/
js/
sass/
images/
templates/
erthreal/
index.html
它将加载模板而不是关联的静态文件。
【问题讨论】:
-
你跑过
collectstatic对吗? -
不,但是当我这样做时,它给了我:[Errno 2] 没有这样的文件或目录:'/home/user1/virtualenvironment/mysite/static'
标签: javascript html css django python-3.x