小编Hat*_*out的帖子

HTML 客户端和 Node.js 服务器之间的变量

我只想将变量从 HTML 页面传递到 Node js,并对数据执行一些计算,然后使用 ejs 将其返回到 HTML 安装 ejs 后:

npm install ejs
Run Code Online (Sandbox Code Playgroud)

我正在尝试传递值为 50“HTML 页面”的变量 temp:

<html>
   <head>
   </head>
<body>
My temperature: <%= temp=50 %>
Temp + 10 : <%= total %>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

和我的nodejs server.js:

var http = require('http');
var ejs = require('ejs');
var fs = require('fs');

http.createServer(function(req,res) {
  res.writeHead(200, {'Content-Type': 'text/html'});

  //since we are in a request handler function
  //we're using readFile instead of readFileSync
  fs.readFile('index.html', 'utf-8', function(err, content) {
    if (err) {
      res.end('error occurred');
      return; …
Run Code Online (Sandbox Code Playgroud)

javascript ejs node.js

5
推荐指数
1
解决办法
8275
查看次数

如何在Django HTML中导入模块?

我有一个django博客。我需要使用附魔来检查博客文章中的文本是否为英文,然后在文本错误更正中使用api。

我将api安装在django博客的虚拟环境中

pip安装pyenchant

项目,并将其包含在已安装的应用程序中,但是在博客base.html中,我尝试加载它并使用它的功能来检查帖子标题是否为英文,但是我什么也没做。如何解决呢?这是我的html代码:

{% load enchant %}

{% dictionary = enchant.Dict("en_US") %}
<p>{% dictionary.check(post.title) %}</p>
Run Code Online (Sandbox Code Playgroud)

当我运行服务器时没有错误,但是html页面上没有任何内容。注意:根据API,在段落标记中应该为True of False。“我在python shell中对其进行了测试。”

python django django-templates django-models

1
推荐指数
1
解决办法
2563
查看次数

如何在节点红色中进行http重定向?

我需要重定向到另一个网址.我使用nodered来请求一个url,然后获取用户名和密码,在cloudant数据库中检查它们,并且在确认它们存在之后,我需要重定向到另一个/ home.是否有重定向的节点?我尝试使用http请求节点,但它只是在json或二进制中获取响应而不重定向url.如何在nodered中重定向?

node-red

1
推荐指数
1
解决办法
2286
查看次数