DEV Community

Bret
Bret

Posted on

Django.... should I be switching around paths?

I’m watching a tutorial by Dennis Ivy, and he switches around paths into their own file. Is that ok?
It kinda messed me up.

I created a file for a app, but idk if I’m doing it right with using it.

Should I have multiple url.py files?

What is a structure for having an a example of 2 apps made?

Top comments (3)

Collapse
 
michaelb profile image
Michael B

I have a separate urls.py for each app! You can then use include to add all the urls.py of an app with a prefix (e.g. from an application i am working on now, 'chat/' is the prefix for the chat app)

The way to think of Django projects vs apps, is that apps are intended to be "full vertical slices" of a web application, so routing, views, models, templates, static files, and so on. It's sometimes hard to dis-entangle everything, but if you can do as much as you can, larger applications are far more manageable.

Collapse
 
yobretyo profile image
Bret

Ok, it messes me up when you go in between 2 files with basically the same name. The tutorial, he copied and pasted only part of a path type file or it was for urls and it messed me up. I got down the command to make a add tho

Collapse
 
michaelb profile image
Michael B

The extra files should go in separate directories

e.g.

apps/
    chat/
         urls.py
         models.py
         views.py
         templates/
         etc...

for a single app called "chat". does that make sense?

That said, all this really only matters if you have an aplpication / team large enough where this sort of code cleanliness is important. If you are just by yourself and just learning then you don't have to bother