分离Django应用程序视图 [英] Separating Django App Views
本文介绍了分离Django应用程序视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果app / views.py文件变得非常大,我应该分开吗?如果是这样,最好的方法是什么?
If the app/views.py file gets very large, should I separate it? If so, what is the best way to do this?
推荐答案
没有通用的最佳方式 。但是对于您的情况,您可以使用 。
There is no generic best way. But there is a right way for your situation.
- 将视图放在自己的文件和导入他们。这是很好的只是看看它如何工作
- 在项目中使一个单独的应用程序维护一组视图
- 创建您自己的通用视图,共享视图共同对于大多数应用程序
- put the views in their own files and import them in your view. This is good just to see how it works
- make a separate app inside the project to maintain a set of views
- create your own generic views which share the views common to most of your apps
只是一个例子:
我建议你开始从模型和工作自己:
Just as an starting example: I recommend you to start from the model and work yourself up:
- 你有多少模型?
- 他们实际上都是相关联还是可以分组?
- 如果可以 strong>将应用程序分解为两个应用程序
- ,这样您也可以拆分视图
- 确定哪些视图功能是类似,并使他们通用。
- how many models do you have?
- Do they actually all relate or can they be grouped?
- if the can be grouped split the app into two apps
- so you'll also split the views
- determine which view functions are similar and make them generic.
这篇关于分离Django应用程序视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文