Django: Breaking up views

前端 未结 3 590
小蘑菇
小蘑菇 2021-02-01 17:52

This is really just a \"best practices\" question...

I find that When developing an app, I often end up with a lot of views.

Is it common practice to br

3条回答
  •  逝去的感伤
    2021-02-01 18:08

    As a general guideline, think about readability and maintainability: the default "views.py" is just a suggestion made by initial scaffolding - you do not have to stick to it.

    Usually, files with thousands of lines of code are difficult to maintain, for this I usually try to decompose bigger modules into smaller ones.
    On the other hand, the division should make sense - splitting related functions into several files, with lots of imports may make maintenance even more difficult.

    Finally, you can also think about completely other ways to simplify your application.
    Do you see duplicated code? Maybe some functionality could be moved in a completely different application? And so on.

提交回复
热议问题