[Django]-Can a django app have more than one views.py?

1👍

Views are just python modules, you can do whatever you want, for instance you can change their names to whatever.py as long as your imports are correct 🙂

And as suggested: find more info here Django: split views.py in several files 🙂

4👍

Yes, you can. A modular way of splitting would be to create a package – views/

- views/
    - first.py
    - second.py
    - __init__.py

and in your __init.py__ add the following:

from .first import *
from .second import *

This way, all your views would be available for urls.py.

0👍

You can totally do that, it is only a convention to use views.py.

Now, the question is: do you really need to create a new file to put your views inside ? Shouldn’t these regrouped in a new application ?

Think of an other person reviewing your code: would the reason of the separation be crystal clear to him ?

Leave a comment