在Pycharm中,我无法获取JSON文件并且无法安装fetch

问题描述 投票:0回答:3

我正在 Pycharm 中开发 Django 项目。我需要在 Javascript 文件中获取 API,但它给了我一个内部服务器错误,并在控制台中显示了获取行的错误。看起来它根本不识别 fetch。

这是我如何在代码中使用 fetch 的示例;

    document.querySelector('#compose-form').onsubmit = function () {
     fetch('/emails', {
              method: 'POST',
              body: JSON.stringify({
                  recipients: in_recipients,
                  subject: in_subject,
                  body: in_body,
              })
            })
            .then(response => response.json())
            .then(result => {
                if (result.message !== "Email sent successfully."){
                  alert(result.error)
                }
            });
        };

我的代码实际上可以在 Vscode 上运行,但无法在 Pycharm 中运行。我试过了

     pip install fetch 

我收到以下错误;

 ERROR: Command errored out with exit status 1:
  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\bilge\AppData\Local\Temp\pip-install-n1v3op9a\fetch\setup.py", line 6, in <module>
    description = file(os.path.join(here, 'README.txt')).read()
NameError: name 'file' is not defined
----------------------------------------
 ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full 
 command output.

也尝试过

        python setup.py egg_info

说:

        can't open file 'setup.py': [Errno 2] No such file or directory

提前谢谢您。

javascript django pycharm fetch
3个回答
2
投票

fetch 需要进行多填充,因为当您编译代码时,您不会添加任何可能需要的新全局或原始属性。 fetch 将是全局命名空间上的一个新属性,因此需要对其进行填充。

所以它们不能用babel编译。在此处查看更多详细信息使用 babel-preset-env 时 Babel 不进行 Polyfilling Fetch


2
投票

没有这样的事

           pip install fetch 

您需要更改设置、语言和框架,并找到 Javascript 库。添加 TypeScript。


0
投票

我不知道@bdemirka你的问题是否解决了,因为我刚刚遇到了Pycharm的问题,我正在学习JavaScript。一切都工作正常然后突然一切都变了

pycharm 似乎无法识别 JavaScript 的

document.querySelector()

到目前为止我尝试过的:

  • 将pycharm恢复为默认值

  • 重新安装节点

  • 按照@mr_nocoding的建议更改设置(设置、语言和框架,并找到Javascript库。添加TypeScript。)

    Pycharm 检测到

    fetch()
    正常。有什么想法吗?

© www.soinside.com 2019 - 2024. All rights reserved.