How do I write a single-file Django application?

后端 未结 11 1889
余生分开走
余生分开走 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:04

    You also may want to take a look at web.py. (Tutorial)

    It's another compact, but powerful web framework.

    Sample from the main page:

    import web
    
    urls = ('/(.*)', 'hello')
    app = web.application(urls, globals())
    
    class hello:        
        def GET(self, name):
            if not name: 
                name = 'world'
            return 'Hello, ' + name + '!'
    
    if __name__ == "__main__":
        app.run()
    

提交回复
热议问题