I am working on a Django project in Pycharm. I need to fetch API in the Javascript file, but it gives me an internal server error and error in the console showing the fetch line. It seems like it is not recognizing fetch at all.
This is an example of how I use fetch in my code;
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)
}
});
};
My code is actually working on Vscode but can't make it work in Pycharm. I tried
pip install fetch
I got the following error;
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.
Also tried
python setup.py egg_info
says:
can't open file 'setup.py': [Errno 2] No such file or directory
Thank you in advance.
There is no such a thing like
pip install fetch
You need to change in the settings, Languages and Frameworks, and find Javascript libraries. Add the TypeScript.