Split views.py in several files

前端 未结 10 858
有刺的猬
有刺的猬 2020-11-27 09:37

My views.py has become too big and it\'s hard to find the right view.

How do I split it in several files and then import it? Does it involve any speed l

10条回答
  •  感动是毒
    2020-11-27 10:02

    Basically, you can put your code, whereever you wish. Just make sure, you change the import statements accordingly, e.g. for the views in the urls.py.

    Not knowing your actual code its hard to suggest something meaningful. Maybe you can use some kind of filename prefix, e.g. views_helper.py, views_fancy.py, views_that_are_not_so_often_used.py or so ...

    Another option would be to create a views directory with an __init__.py, where you import all subviews. If you have a need for a large number of files, you can create more nested subviews as your views grow ...

提交回复
热议问题