KeyError at/'assets' 和 ModuleNotFoundError:没有名为 'webpack_loader' 的模块 [英] KeyError at / 'assets' and ModuleNotFoundError: No module named 'webpack_loader'
问题描述
当我在 http://127.0.0.1:8000/ 我收到这个错误
When I am at http://127.0.0.1:8000/ I'm getting this error
KeyError at/
KeyError at /
'资产'
在 settings.py
已安装的应用
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
#own
'rest_framework',
'rest_framework.authtoken',
'allauth',
'allauth.account',
'allauth.socialaccount',
'rest_auth',
'rest_auth.registration',
'crispy_forms',
'webpack_loader',
'users',
'questions',
Webpack 加载器
WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': 'dist/',
'STATS_FILE': os.path.join(BASE_DIR, 'frontend', 'webpack-stats.json'),
}
}
在模板文件夹 (index.html)
{% load render_bundle from webpack_loader %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>QuestionTime</title>
</head>
<body>
<h1>Vue JS</h1>
<div id="app"></div>
{% render_bundle 'app' %}
</body>
</html>
我也有 vue.config.js 文件
(旧见更新)
在终端它说这个
asset = assets['assets'][chunk]
asset = assets['assets'][chunk]
关键错误:'资产'
终端(更新)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'webpack_loader'
更新:卸载了 Django-webpack5-loader,因为它没有达到我希望的效果.
UPDATED: Uninstalled Django-webpack5-loader since it didn't do what I hoped.
但现在我又犯了一个错误
But now I get another error
见上文终端(更新)"
更新 2
现在所有错误都消失了,唯一的问题是,我的 vue 没有显示在浏览器中.
All errors are gone now, only issue is that, my vue doesn't show up in the browser.
推荐答案
错误似乎在 webpack 包中.这个答案应该会有所帮助:Django Webpack Loader: Assets"密钥错误?
The error seems to be in the webpack package. This answer should help: Django Webpack Loader: "Assets" KeyError?
这篇关于KeyError at/'assets' 和 ModuleNotFoundError:没有名为 'webpack_loader' 的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!