如何编写单文件Django应用程序? [英] How do I write a single-file Django application?
问题描述
$ python myapp.py
你可以假设我不会呈现HTML,所以我不需要模板(我将返回 JSON 或其他一些自动生成的字符串)
您可能需要考虑Simon Willison的图书馆:
从 readme :
djng是一个依赖宏框架的微框架(Django )。
我对mi的定义cro框架:可以让您在单个模块中创建一个完整的
Python Web应用程序:import djng
def index(request):
return djng.Response('Hello,world')
如果__name__ =='__main__':
djng。 serve(index,'0.0.0.0',8888)
[...]
I want to write a very small Django application in a single file, requiring all the appropriate modules and stuff, and then be able to run that as a normal Python script, like this:
$ python myapp.py
You can assume I won't render HTML, so I don't need templates (I'll return JSON or some other auto-generated string).
You might want to consider Simon Willison's library:
From the readme:
djng is a micro-framework that depends on a macro-framework (Django).
My definition of a micro-framework: something that lets you create an entire Python web application in a single module:
import djng def index(request): return djng.Response('Hello, world') if __name__ == '__main__': djng.serve(index, '0.0.0.0', 8888)
[...]
这篇关于如何编写单文件Django应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!