Файловая структура Django с помощью react
Я новичок в Django и react. Я следую приведенному ниже руководству и столкнулся с проблемой. Я думаю, что проблема в моей файловой структуре. Руководство, которому я следую
Структура файлов в руководстве такова
├── manage.py
├── mysite
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── myapp <----- a normal Django app
│ ├── __init__.py
│ ├── models.py
│ ├── urls.py
│ └── views.py
├── assets <----- our front-end project source
│ ├── javascript
│ └── styles
├── static <----- our front-end project outputs (and other Django static files)
│ ├── css
│ ├── images
│ └── js
└── templates <----- our Django template files
└── myapp
и моя файловая структура такова:
|myproject
├── manage.py
├── .gitignore
├── package-lock.json
├── package.json
├── webpack.config.js
│
├── node_modules
│ ├── .....
├── myproject
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── myapp
│ ├── __init__.py
│ ├── models.py
│ ├── urls.py
│ └── views.py
├── js
│ ├── index.js
├── static
│ ├── css
│ ├── images
│ ├── js
| ├── index-bundle.js
└── templates
├── myapp
├── hello_webpack.html
Я следовал руководству шаг за шагом до добавления файла hello_webpack.html.
При запуске сервера я получаю следующую ошибку: TypeError("Invalid path type: %s" % type(value).name) TypeError: Недопустимый тип пути: list
Мой /js/index.js
function component() {
const element = document.createElement('div');
element.innerHTML = 'Hello webpack';
return element;
}
document.body.appendChild(component())
webpack.config.js
const path = require('path');
module.exports = {
entry: './js/index.js', // path to our input file
output: {
filename: 'index-bundle.js', // output bundle file name
path: path.resolve(__dirname, './static'), // path to our Django static directory
},
};
myproject/settings.py
import os
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [STATICFILES_DIRS,],
'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',
],
},
},
]
myproject/urls.py
from django.contrib import admin
from django.urls import path
from django.views.generic import TemplateView
urlpatterns = [
path('admin/', admin.site.urls),
path('hello-webpack/', TemplateView.as_view(template_name='hello_webpack.html'))
]
templates/hello_webpack.html
{% load static %}
<!doctype html>
<html>
<head>
<title>Getting Started with Django and Webpack</title>
</head>
<body>
<script src="{% static 'index-bundle.js' %}"></script>
</body>
</html>
Я пробовал изменить STATICFILES_DIRS в settings.py, но не могу заставить его работать. Я буду очень признателен за любую помощь.