嵌入一个基于Python的基于Web的shell(Werkzeug?) [英] Embedding a Python web-based shell (Werkzeug?)
问题描述
我正在寻找一种在网页中嵌入python解释器的方法。具体来说,可以访问Django模板范围的textarea / REPL类似的东西。
I'm looking for a way to embed a python interpreter in a web page. Specifically, something similar to a textarea/REPL having access to the scope of a Django template.
Werkzeug 做类似的事情,但是我无法找到有关嵌入过程的任何示例或文档。帮助是非常受欢迎的!
Werkzeug Does something similar, but I'm unable to find any example or documentation regarding the embedding process. Help is very welcome!
推荐答案
如果你使用Apache / mod_wsgi,你需要做的只是修改你的.wsgi文件包括:
If you are using Apache/mod_wsgi, all you need to do is modify your .wsgi file to include:
from werkzeug.debug import DebuggedApplication
和
application = get_wsgi_application()
application = DebuggedApplication(application, evalex=True)
然后,您可以访问example.com/console的python shell注意控制台之后的空间!)
Then you can access the python shell at "example.com/console " (Note the space after console!)
您还可以使Django无法捕获的任何服务器错误将被werkzeug添加到您的项目设置中.py:
You can also make it so that any server errors which Django doesn't catch will be caught by werkzeug by adding this to your project settings.py:
DEBUG_PROPAGATE_EXCEPTION = True
请注意,此控制台可能是安全隐患。
Do note that this console could be a security hazard.
这篇关于嵌入一个基于Python的基于Web的shell(Werkzeug?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!