How do I write a single-file Django application?

后端 未结 11 1881
余生分开走
余生分开走 2020-12-14 19:29

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, li

11条回答
  •  佛祖请我去吃肉
    2020-12-14 20:06

    You might want to consider Simon Willison's library:

    • djng—a Django powered microframework

    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)
    

    [...]

提交回复
热议问题