Django: Breaking up views

前端 未结 3 588
小蘑菇
小蘑菇 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:05

    Another option would be to move some of the functionality into one or more apps. This would allow you to move also forms and templates and keeping things structurized. You don't necessarily need to move the models which saves you from model and data migration.

    For example you could have the following structure:

    main_app/
      |_models.py
      |_views.py
      |_forms.py
      |_urls.py
      |_templates/
    
    sub_app_1/
      |_views.py
      |_forms.py
      |_urls.py
      |_templates/
    
    sub_app_2/
      |_views.py
      |_forms.py
      |_urls.py
      |_templates/
    

提交回复
热议问题