【发布时间】:2021-05-19 12:27:24
【问题描述】:
我的应用由 django 和 react 组成,最后捆绑到静态 (.js) 文件中。 我的目标是为其设置一个 nginx,但现在我只想在 uwsgi 中运行以查看它是否有效。 Aaaaand 它根本不起作用。我相信加载这个 webpack 正在编译的捆绑文件存在问题。
与 uwsgi 的连接正常,服务器已启动并正在运行,但是当连接到 127.0.0.1:8080 时,我得到(在 Mozilla 中):
The resource from “http://127.0.0.1:8080/static/frontend/main.js”
was blocked due to MIME type (“text/html”) mismatch
(X-Content-Type-Options: nosniff).
# and another
GET http://127.0.0.1:8080/static/frontend/main.js
HTTP/1.1 404 Not Found
Content-Type: text/html
X-Frame-Options: DENY
Content-Length: 3277
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
Vary: Origin
我找到了类似的话题:Difference between static STATIC_URL and STATIC_ROOT on Django
但与python manage.py collectstatic 搞混并没有解决任何问题。
我有这行代码来管理静态文件:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join('/app/label_it/front/static/frontend/')
这就是我开始 uwsgi 连接的方式:
python manage.py collectstatic --no-input
uwsgi --http 0.0.0.0:8080 --master --enable-threads --module label_it.wsgi
除了collectstatic,我还尝试过使用<script src"static_file_path"></script>这个静态路径:
<script src="../../static/frontend/main.js"></script>
# and
<script src="{% static "frontend/main.js" %}"></script>
什么都没有。
感谢任何线索!
编辑:
我的文件结构:
【问题讨论】:
-
你能附上你的 django 项目文件结构的截图吗?我想看看 react 前端文件相对于 django 应用程序的存储位置
-
@Danoram 已更新。在
/front/static/frontenddir 中是捆绑的静态文件
标签: django webpack django-rest-framework uwsgi wsgi