66

I often see people claiming their backend is implemented in Django, but isn't Django supposed to be for the frontend? I'd assume the backend refers to the business logic where the frontend refers to the presentation. Am I missing something?

Kar
  • 6,063
  • 7
  • 53
  • 82
  • 1
    The first page on it's [site](https://www.djangoproject.com/) tells you what django is: a high-level Python Web framework – Eugene Yarmash Jan 31 '12 at 14:39

3 Answers3

116

Neither.

Django is a framework, not a language. Python is the language in which Django is written.

Django is a collection of Python libs allowing you to quickly and efficiently create a quality Web application, and is suitable for both frontend and backend.

However, Django is pretty famous for its "Django admin", an auto generated backend that allows you to manage your website in a blink for a lot of simple use cases without having to code much.

More precisely, for the front end, Django helps you with data selection, formatting, and display. It features URL management, a templating language, authentication mechanisms, cache hooks, and various navigation tools such as paginators.

For the backend, Django comes with an ORM that lets you manipulate your data source with ease, forms (an HTML independent implementation) to process user input and validate data and signals, and an implementation of the observer pattern. Plus a tons of use-case specific nifty little tools.

For the rest of the backend work Django doesn't help with, you just use regular Python. Business logic is a pretty broad term.

You probably want to know as well that Django comes with the concept of apps, a self contained pluggable Django library that solves a problem. The Django community is huge, and so there are numerous apps that do specific business logic that vanilla Django doesn't.

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
Bite code
  • 578,959
  • 113
  • 301
  • 329
  • If the business logic is separated from the presentation in a 3-tier architecture, then there should be no need to use Django for the business logic, right? All the 'webby' stuff are only present in the presentation layer, right? – Kar Jan 31 '12 at 14:36
  • @Kate: In django, you would expect business logic to be separated from presentation logic. – Marcin Jan 31 '12 at 14:43
  • Django embed the tools for the business logic as well: the ORM and the forms. You don't have to use them, but they will make you dev much faster if you do. – Bite code Jan 31 '12 at 16:37
  • 1
    @kate, I added some additional explanations. Please note that an academic definition of the architecture will not help you as much as actually giving it a try. In the end, it's more about getting things done than talking about things. Abstraction are cleared with you actually used them. – Bite code Jan 31 '12 at 16:46
  • What is an ORM? – Jan M. Apr 19 '23 at 14:16
14

It seems you're actually talking about an MVC (Model-View-Controller) pattern, where logic is separated into various "tiers". Django, as a framework, follows MVC (loosely). You have models that contain your business logic and relate directly to tables in your database, views which in effect act like the controller, handling requests and returning responses, and finally, templates which handle presentation.

Django isn't just one of these, it is a complete framework for application development and provides all the tools you need for that purpose.

Frontend vs Backend is all semantics. You could potentially build a Django app that is entirely "backend", using its built-in admin contrib package to manage the data for an entirely separate application. Or, you could use it solely for "frontend", just using its views and templates but using something else entirely to manage the data. Most usually, it's used for both. The built-in admin (the "backend"), provides an easy way to manage your data and you build apps within Django to present that data in various ways. However, if you were so inclined, you could also create your own "backend" in Django. You're not forced to use the default admin.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
5

(a) Django is a framework, not a language

(b) I'm not sure what you're missing - there is no reason why you can't have business logic in a web application. In Django, you would normally expect presentation logic to be separated from business logic. Just because it is hosted in the same application server, it doesn't follow that the two layers are entangled.

(c) Django does provide templating, but it doesn't provide rich libraries for generating client-side content.

Marcin
  • 48,559
  • 18
  • 128
  • 201
  • But if the business logic is in the web app (single-tier architecture?) then there's no distinction between the front-end and the back-end, right? It's just a single-tier. – Kar Jan 31 '12 at 14:30
  • @Kate: You could have all your presentation logic in the browser, business logic in a django middle tier, and a database layer. You could also have a separate django project providing backend services as well. – Marcin Jan 31 '12 at 14:33