This is probably obvious to experienced users but I have been dealing with Django for only several days.
Question: Where do you put global views, i.e. for the main page?
I followed the tutorial where you only create views for an app called polls. And it is also written that as much stuff as possible should be put in decoupled apps to make them portable. I found nothing about a view for the main page. So should I put my main stuff in project_name/project_name/views.py or create a separate app, put the views in project_name/globalapp/views.py and then map the '^$' URL to global.main?
I guess I can do whatever I want but I wonder whether there is a common way to do it because it has advantages I haven't realized yet.
I found this question but the answer doesn't seem to be clear about this.
This is a matter of personal preference. My own rule-of-thumb is:
If your global pages are simple collections of links to your apps or data from them then the easiest way is to put the views for them in a file at the project level, right next to your settings.py and urls.py. You also put custom middleware and custom context processors in files in the same location.
If your global pages are any more complicated than that (for example they need their own models or forms or ...) then put them in a separate app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With