Reputation: 6089
In Django you name your files like models.py
, views.py
, urls.py
and so on. I wonder, if this naming convention is mandatory for Django. Will Django's functionality break if you place your models in a file called foo.py
? I mean, only the import-line should change, right? Or is there any magic with this named files done by the framework?
Of course, I won't give my files shitty names; but I am just curious.
Upvotes: 2
Views: 331
Reputation: 5496
The best is to create modules instead for a couple of reasons:
So you'd have:
- my_application
- urls
- sub_set_urls_1.py
- etc.
- models
__init__.py <= import your models in here
sub_set_models_1.py
etc.
- views
sub_set_views_1.py
etc.
It's a bit more involved for the models
, you need to import the models in __init__.py
. Another way is to have a models.py
file and put your models somewhere else: Split models.py into several files
Upvotes: 1
Reputation: 369444
views, urls can be configured.
<project>.settings.ROOT_URLCONF
, and include your apps' urls.But for models, there's assumption about the model module name in the django code and other third-party apps. (https://github.com/django/django/blob/stable/1.7.x/django/apps/config.py#L9)
Upvotes: 3