How do I write a single-file Django application?

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

    Well, the easiest way to do that is to mimic the django project arbo in one file. So in one module, assure there is :

    Root_module :
        Root_module.settings
        Root_module.urls
        Root_module.app_in_the_module
        Root_module.app_in_the_module.models
        Root_module.app_in_the_module.views
    

    Then code is as a normal Django project. What you must know is that Django does not need anything to be in a specific place. Standard names and paths are at beat, convention, at worst, shortcut to prevent you from defining a setting.

    If you know Django very well, you don't even need to mimic the arbo, just write you django app making all the data from the above modules interconnected the way they should be.

提交回复
热议问题