I know this discussion is old, and it’s been going on for a while. Some people are in favor, most are against it, but I’m not here to simply ask to add urls.py to the app_templates. I’m here to ask for a small change that I’ve already made, tested, and works well.
My idea is this: since many don’t like the idea of automatically adding the urls.py, I, as a beginner developer, see a great need for this file. But how can we do this, since most people don’t like the idea of it being created automatically? Simple, when using “python manage.py startapp example”, we can simply add an argument to the command, making it like this: “python manage.py startapp example --createurls”. This is a simple example of how to end all the discussions this generates once and for all.
I am creating a prototype in the startapp.py file (core). Basically, I receive this argument as a parameter, make a condition, and if it returns true, I use a variable “urls_content”, go to the app directory, and with the context manager, I write the urls_content to the file. If it returns false, it simply does nothing.
I apologize if this has already been discussed or if I have stated a concept incorrectly, I am a beginner with Django and Python as well.
Czue, in my opinion, this would only add value to the project, since creating urls.py wouldn’t be mandatory, but developers who want convenience and will use the file could simply use a command to have it created automatically.
I understand that, and I know it sounds like a simple/obvious thing to add. Believe me, I’m on your side, and I would support this change.
The pushback I think you will get will be along the lines of:
Why just this option? Shouldn’t we add more options?
Shouldn’t there just be one way to do things? We should just pick a default and use it everywhere.
We’ll now have to maintain mulitple options in the docs, tutorials, etc.
We’re doing this template thing in one way in startproject and a totally different way in startapp…
Ultimately, the lesson I learned was that things that sound like simple changes, aren’t. And without getting too much in the weeds of how the django project makes decisions, I’m suggesting that based on what I understand the change-process of the project to be, that this might be a good topic to combine with the startproject DEP. That way there is (hopefully) at least a consensus that emerges on how we are going to be able to update and manage project and app templates moving forwards. Then we drop this option into that framework.
Just my two cents having gone through all this already…
It’s much better to keep related conversations in one place, rather than re-raising the same topic in a new thread.
As far as I can see there’s no immediate consensus around a change here. I agree with @cory, the best way forward is the WIP DEP, which has more/better template support in its likely scope.