简体   繁体   English

如何将数据从 HTML 发送到 python 并将结果返回到 HTML?

[英]how to send data from HTML to python and get the result back to HTML?

I know nothing about the interface between HTML and python so I come here to ask for help hope you guys can help me.我对HTML和python之间的接口一无所知,所以我来这里寻求帮助希望你们能帮助我。

HTML are now post on apache server,and I visit this web by the address " http://127.0.0.1/name.html ". HTML 现在发布在 apache 服务器上,我通过地址“ http://127.0.0.1/name.html ”访问此网站。

Here is what I want to achieve:这是我想要实现的目标:

There is a form on HTML getting the data,and by clicking the button "submit",the data should be send to python.exe,and the python.exe runs itself and send the result back to HTML(by poping a new dialog). HTML上有一个获取数据的表单,点击“提交”按钮,数据应该发送到python.exe,python.exe自己运行并将结果发送回HTML(通过弹出一个新对话框) .

I searched on the Internet and was wondering will Django help??我在网上搜索,想知道 Django 会帮忙吗??

Is this even possible?Can anybody help me ?这甚至可能吗?有人可以帮助我吗?

After learning about Django,I realised this function by myself.在学习了Django之后,我自己实现了这个功能。

Here's some suggestions for someone who might have the same problems:对于可能遇到相同问题的人,这里有一些建议:

1.Django can help solve this problem:You get the data from HTML,and post/get to a new url; 1.Django可以帮助解决这个问题:你从HTML中获取数据,然后post/get到一个新的url;

2.urls.py will control the direction and excute coressponding python program according to the address of the above url mentioned;by doing this you can do some handling with data; 2.urls.py会根据上面提到的url地址控制方向并执行核心响应python程序;这样就可以对数据做一些处理;

3.use HttpResponse or Render to send back data to HTML from python. 3.使用 HttpResponse 或 Render 将数据从 python 发送回 HTML。

This is just the approximate rout of the whole process and there surely will be some better solutions as long as we keep learning Django and grasp the virtue.这只是整个过程的大概路线,只要我们继续学习Django,掌握它的优点,肯定会有更好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM