I have been reading some django tutorial and it seems like all the view functions have to go in a file called “views.py” and all the models go in “models.py”. I fear that I might end up with a lot of view functions in my view.py file and the same is the case with models.py.
Is my understanding of django apps correct?
Django apps lets us separate common functionality into different apps and keep the file size of views and models to a minimum? For example: My project can contain an app for recipes (create, update, view, and search) and a friend app, the comments app, and so on.
Can I still move some of my view functions to a different file? So I only have the CRUD in one single file?
First, large files are pretty common in python. Python is not java, which has one class per file, rather one module per file.
Next,
views, even as the standard used, is a python module. A module need not be a single file. It can be a directory containing many files, and__init__.pyAnd then,
views.pyis only a convention. You, the application programmer are referring to it, and django itself doesn’t refer anywhere. So, you are free to put it in as many files and refer appropriate functions to be handed over, the request to, in theurls.py