我正在尝试部署一个Django--对弹性豆柄作出反应,部署显示为成功,但只给了我一个白色的空页面,(api调用正常工作)。
检查/var/log/nginx/error.log显示:
2020/08/06 02:58:06 [error] 4461#0: *11 open() "/var/app/current/staticbundle.js" failed (2: No such file or directory)因此,我理解它试图找到bundle.js,但在错误的路径上,我不知道如何修复,应该如下所示:
/var/app/current/static/bundle.js我以为它没有正确地构建静态文件夹,但是它确实构建了,结果是这样的:
current
│
└───static
│ │ bundle.js
│ │ index.html
│
└───...这是我的项目设置
1.1 settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'1.2 urls.py
from django.contrib import admin
from django.urls import path, include, re_path
from django.views.generic import TemplateView
urlpatterns = [
path('api/', include('backend.urls')),
re_path(r'^.*', TemplateView.as_view(template_name='index.html')),
]1.3 django.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: cerbero.wsgi
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static/: static/
container_commands:
01_node_install:
command: "curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash - && sudo yum -y install nodejs"
ignoreErrors: false
02_npm_install:
command: "npm install"
ignoreErrors: false
03_react_collect:
command: "npm run build"
ignoreErrors: false2.WebPack方:- webpack.config.js
// webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './frontend/src/index.js',
watch : false,
devtool : 'source-map',
output : {
filename: 'bundle.js',
path : path.resolve(__dirname, 'static/'),
publicPath: '/',
},
devServer: {
contentBase: './',
inline: true,
hot: true,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './frontend/templates/frontend/index.html',
filename : './index.html',
minify: false
})
]
};<!doctype html>
{%load static %}
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cerbero</title>
</head>
<body>
<div id="app"></div>
<script src = "{% static '/bundle.js' %}"></script>
</body>
</html>我真的不知道这个问题是属于姜戈,webpack,还是反应
发布于 2020-08-06 08:19:19
urlpatterns = [
path('api/', include('backend.urls')),
re_path(r'^.*', TemplateView.as_view(template_name='index.html')),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)https://stackoverflow.com/questions/63277227
复制相似问题