# Whats the correct way to add logic to a view

**URL:** <https://forum.djangoproject.com/t/whats-the-correct-way-to-add-logic-to-a-view/11027>\
**Category:** Using Django\
**Created:** [December 14, 2021, 12:20pm UTC](https://forum.djangoproject.com/t/whats-the-correct-way-to-add-logic-to-a-view/11027 "2021-12-14T12:20:38Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 14, 2021, 1:45pm UTC](https://forum.djangoproject.com/t/whats-the-correct-way-to-add-logic-to-a-view/11027/2 "2021-12-14T13:45:06Z")

</div>

First, never lose sight of the fact that a Django view is just a Python function that takes a request and returns a response. There’s nothing special or magical about it.

This means you have all the “code organization” facilities available as with any other Python program.

Yes, it’s absolutely ok to break the functionality of the view down into different modules.

Where you physically place that logic _is_ a topic open for (a lot of) discussion. For examples, see the discussions here - [Where to put business logic in Django?](https://forum.djangoproject.com/t/where-to-put-business-logic-in-django/282) and here - [Structuring large/complex Django projects, and using a services layer in Django projects](https://forum.djangoproject.com/t/structuring-large-complex-django-projects-and-using-a-services-layer-in-django-projects/1487). (So no, this is _far_ from being a “stupid question” - it wouldn’t generate this amount of conversation if it were.)

Regardless of the organizational structure you adopt, I think it’s _most_ important that you remain consistent within and among projects. Given Python’s flexibility, the issue is that there’s so many different ways of doing this, you want to “minimize surprise” when you (or a teammate) need to go back into the code later to maintain or update it. And _that_ implies having a consistent pattern applied throughout.

---

_[View the full topic](https://forum.djangoproject.com/t/whats-the-correct-way-to-add-logic-to-a-view/11027)._
