Separating Django App Views

前端 未结 4 1133
一向
一向 2021-02-04 06:17

If the app/views.py file gets very large, should I separate it? If so, what is the best way to do this?

4条回答
  •  别那么骄傲
    2021-02-04 06:39

    Some developers make their views a python package instead of a module. This simply means making a directory called views in your application then placing each view in its own module (file) in that package.

    Then you create an __init__.py file (which is what makes it a package). This file can be empty or it can be import all the view modules into its own namespace.

    If it is empty you would have to import each view you need directly otherwise you can import it just as though it were a views.py module.

提交回复
热议问题