【问题标题】:Java Script working on local machine but not working on google cloud port 80Javascript 在本地机器上工作但不能在谷歌云端口 80 上工作
【发布时间】:2020-11-29 21:55:02
【问题描述】:

我正在尝试在谷歌云上部署 django 网络应用程序。我已经在本地机器上进行了测试,它似乎工作正常。但是在我在谷歌云端口 80 上测试后,javascripts 不起作用。

这是我引用 javascript 函数的 django 表单

class ScqQuestionForm(forms.ModelForm):
class Meta:
    model = Single_ans_q
    fields=['question_text']
    widgets = {
    'question_text' : forms.Textarea(attrs={
        'placeholder' : 'Question',
        'cols' : 140,
        'rows' : 6,
        'name':'questioninput',
         'id': 'questioninput' ,
         'onkeyup':'func_output()',
         'required': 'True',    



        })
    }

我的javascript是

window.func_output = function () {
    button.disabled = true;
    output.innerHTML = input.value.trim();
    MathJax.texReset();
    MathJax.typesetClear();
    MathJax.typesetPromise([output]).catch(function (err) {
      output.innerHTML = '';
      output.appendChild(document.createTextNode(err.message));
      console.error(err);
    }).then(function () {
      button.disabled = false;
    });
  }

我在控制台中收到此错误

console error for javascript.

此外,在控制台中,我看到了我的函数

function in error console

该错误仅发生在谷歌云部署上,在本地机器上运行平稳。

【问题讨论】:

    标签: javascript google-cloud-platform django-deployment


    【解决方案1】:

    你有没有检查你是否打开了 80 端口?

    【讨论】:

    • 你能指导一下吗?我们的页面正在渲染,但 javascript 无法正常工作
    • 你能把你的网络应用的链接发给我吗?
    • 要打开端口 80,您需要创建防火墙规则并将规则分配给您的 VM 实例,并使用 networking tag。可以在此文档中找到更多信息:cloud.google.com/vpc/docs/using-firewalls
    • 谢谢。我打开了 80 端口,但 JavaScript 仍然无法正常工作。我如何向您发送应用程序的链接? GitHub链接可以吗?
    • 你尝试连接80端口直接登录虚拟机吗?在端口上执行curl localhost 以对其进行测试。您至少可以验证您的应用程序是否在您的虚拟机上运行! (你真的在计算机上运行你的代码吗?)另一个问题:你能分享你的 django 配置的代码吗?
    猜你喜欢
    • 2019-01-17
    • 1970-01-01
    • 2019-04-25
    • 2021-02-18
    • 1970-01-01
    • 2021-10-29
    • 2013-08-18
    • 2012-10-03
    • 2017-08-22
    相关资源
    最近更新 更多