0

我同时运行 vue 和 django。我已经安装了 webpack_loader 并将其安装在已安装的应用程序中。我在settings.py中有 WEBPACK_LOADER

WEBPACK_LOADER = {
        'DEFAULT': {
            'BUNDLE_DIR_NAME': 'dist/',
            'STATS_FILE': os.path.join(BASE_DIR, 'frontend', 'webpack-stats.json'),
        }
}

frontend 是创建 vue 时的名称。这里有更多细节KeyError at / 'assets' 和 ModuleNotFoundError: No module named 'webpack_loader'

我的页面来源来自http://localhost:8000/看起来像这样

<!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>

    <noscript>
        <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    
    <!-- built files will be auto injected -->
    <script type="text/javascript" src="http://0.0.0.0:8080/bundle.js" ></script>

</body>
</html>

我的页面来源来自http://localhost:8080/看起来像这样

<!DOCTYPE html>
<html lang="">
  <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">
    <link rel="icon" href="/favicon.ico">
    <title>hello-vue</title>
  <link href="/js/about.js" rel="prefetch"><link href="/js/app.js" rel="preload" as="script"><link href="/js/chunk-vendors.js" rel="preload" as="script"></head>
  <body>
    <noscript>
      <strong>We're sorry but hello-vue doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  <script type="text/javascript" src="/js/chunk-vendors.js"></script><script type="text/javascript" src="/js/app.js"></script></body>
</html>

当我使用(django-webpack-loader 1.0.0)时,我得到KeyError at /

当我使用 (django_webpack-loader 0.7.0) 时,我没有收到任何错误,但 vue 代码没有显示(但我在localhost:8080看到它)。

4

1 回答 1

0

刚开始工作今天,我什么都没做,就开始工作了。我尝试了 2 次用相同的代码创建一个新项目,再次下载了所有的东西。

没用。但是后来我的vue代码突然停止工作了。我打开和关闭了服务器。然后我看到我的vue代码已经更新了。然后我去 localhost:8000 看看它是否有效,它确实有效。

我相信上帝修复了它。不知道还会是什么。

于 2021-06-14T06:29:19.460 回答