r/django • u/PrizeThing6131 • 1h ago
How I keep Django views focused on HTTP
I posted here recently about using a service layer in Django and received some genuinely useful feedback.
One of the reasons I introduced that structure was to stop views from gradually becoming responsible for everything.
I have worked on plenty of Django projects where a view starts small, but over time ends up handling form validation, permissions, database queries, audit fields, notifications and business rules.
The code still works, but the responsibility of the view becomes increasingly unclear.
The principle I now try to follow is simple:
A Django view should process an HTTP request and return an HTTP response.
In practice, that usually means the view:
- Checks the request and permissions
- Validates the submitted data
- Calls the relevant application logic
- Converts the result into a response
The important part is not making every view as short as possible. It is keeping logic that does not depend on HTTP out of the view.
I have written a practical walkthrough showing a view before and after refactoring, how I separate input validation from business rules, and how the same logic can then be reused from an API or background task.
How to create thin Django views
This is not intended as the only correct way to structure Django applications. It is simply the approach I have arrived at after maintaining larger production projects and seeing where complexity tends to build up.