Monday, September 18, 2023

RE: Splitting and into a directory rather than single files

I like the following method because it lets me start a project with a single file of views per app and then later when it grows, split it into named files in a 'views' directory - without needing to adjust other code which imports them.

1. Create a views directory in the app dir

2. Create in the new directory

3. Move the monster into ./views renaming it to or something similar.

4. Split into as many useful individual views files as desired - including separate utilities file(s) etc.

5. In import each view used by your using lines like ...

   from .filename import ViewName

Obviously, multiple views can be grouped into the same file so long as they are imported into

6. In you can then say ...

    import appname.views as appname_views

... if that's not what you do already!

(Unsigned mail from my phone)

-------- Original message --------
From: 'Simon Connah' via Django users <>
Date: 18/9/23 22:27 (GMT+10:00)
Subject: Splitting and into a directory rather than single files


I have an app which has a lot of views and URLs and keeping them in just one file makes it really hard to manage because it is so long. I'd like to make a views and URLs folder which will allow me to break up views and URLs into different categories but I'm not sure what the best way to go about doing that is.

Can someone point me in the right direction please?

Thank you!


You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

No comments:

Post a Comment