如何将现有脚本集成到 Django 中?
我刚刚接触到 Django 框架,我想在我的团队的许多基于系统的 Perl/Python/wlst 脚本中使用这个框架。如何获取正常的命令行输出并使其近乎实时地输出到浏览器?我研究过序列化,但似乎找不到任何好的教程。我只是在寻找有关如何制作普通 Python/Perl 脚本并使其与基于 Django 的网站一起使用的建议。
具体来说:我有一个脚本,可以将用户添加到 weblogic 域的角色组中。我想让你填写表格,它连接到服务器完成工作并返回输出。唯一的问题是连接可能需要一点时间。
I have just been introduced to the Django framework and I would like to use this framework for a lot of my system based Perl/Python/wlst scripts for my group. How can I take the normal command line output and have it output the browser in near real time? I have looked into serialization but I can't seem to find any good tutorials. I am just looking for suggestions on how to make a normal Python/Perl script and make it work with a Django based web site.
Specifically: I have a script that will add a user to a group to a role for a weblogic domain. I want to make it so that you fill in the form, it connects to the server does the work and returns the output. The only thing is that it can take a little bit for it to connect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想在网络浏览器中执行 siplay 外部脚本结果吗?然后,我建议您让这些脚本将结果写入数据库,然后使用 django 模型来获取并显示信息。
如果您想在用户每次打开网页时执行脚本并显示结果,请使用以下 python 代码:
You want do siplay external script results in the web browser? Then, I suggest you make those scripts write their results to database and then use django models to fetch and display the info.
If you want to execute the script each time user opens the webpage and display a result, use this python code:
我认为你必须更具体一点。
如果您想在浏览器中输出“操作”的结果,则必须使用呈现模板的
视图
。并引用 django 的 关于视图的文档:
因此,如果您有一个可用的 python 函数/脚本,您可以将其导入您的视图中,并将结果通过管道传输到您的模板。
I think you have to be a bit more specific.
If you want to output the results of an 'operation' in the browser you have to use a
view
that renders a template.And quoting django's docs on views:
So, if you have a working python function/script you can import it in your view and pipe the results that way to your template.