1
我想包含不在帶應用程序中的靜態文件,但在一個單獨的目錄中,名爲static。Django靜態文件404(未找到)
該目錄包含一個構建目錄,其中包含CSS & JS目錄。
除了CSS和JS目錄內的文件外,我還想包含縮小的文件,如jQuery,react和瀏覽器,這些文件位於bower_components目錄中。
我的項目結構如下:
Music/
├── band/
│ ├── migrations/
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── serializers.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── music/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ ├── views.py
│ └── wsgi.py
├── node_modules/
├── static/
├──── static/
│ ├── bower_components/
│ ├── build/
│ ├── css/
│ ├── images/
│ └── js/
├── templates/
├── band/
├── MasterPages/
├── index.html
我音樂內settings.py包含以下內容:
STATIC_URL = '/static/'
STATIC_ROOT = 'C:/Users/Broski/PycharmProjects/Music/static'
MEDIA_ROOT = 'C:/Users/Broski/PycharmProjects/Music/upload'
這MasterPage.html文件位於MasterPages目錄下模板:
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Music</title>
<link rel="stylesheet" href="{% static 'build/css/main.css' %}" type="text/css" />
</head>
<body>
{% block content %}
{% endblock %}
<script src="{% static 'bower_components/jquery/dist/jquery.min.js' %}"></script>
<script src="{% static 'bower_components/react/react.min.js' %}"></script>
<script src="{% static 'bower_components/babel/browser.min.js' %}"></script>
<script type="text/babel" src="{% static 'build/js/indexReact.js' %}"></script>
</body>
</html>
當我加載網站時,模板呈現,但靜態文件沒有。我收到一個404錯誤。
GET http://127.0.0.1:8000/static/css/main.css
127.0.0.1/:22 GET http://127.0.0.1:8000/static/bower_components/jquery/dist/jquery.min.js
127.0.0.1/:23 GET http://127.0.0.1:8000/static/bower_components/react/react.min.js
127.0.0.1/:26 GET http://127.0.0.1:8000/static/bower_components/babel/browser.min.js 404 (Not Found)
正如你所看到的,我需要的反應,jQuery和瀏覽器正確加載繼續此YouTube教程:
Building a website with Django and React.js Video 1: Defining our project structure
謝謝