Django Framework for Frontend and Backend?

Hi, i have some Questions about using Django for Frontend and Backend Development. I would like to develop a web app using django as a framework. Django is typically used for the server side.
My question would be if i can create a dynamic UI with Django without using JavaScript. Can the same goals be achieved if I use django for the frontend or is it smarter to use JavaScript.

Django itself only runs on the server, it does not run in the browser. Any form of dynamic activity in the browser requires JavaScript.

Thanks for the quick reply. In this case I would have to add a JS file to the existing templates (HTML and CSS) in my Django project? How would the communication between frontend and backend work, since I have everything in one Django project? Are APIs still necessary?

Yes - a very common thing to do. (In fact, the Admin does it when it’s using jQuery.) From Django’s perspective, it’s just another static file to be referenced in the HTML being rendered and returned to the browser.

The communication doesn’t change, regardless of the physical organization of the code. JavaScript in a browser issues http requests, which Django responds to. Django doesn’t care whether the request is being issued by the browser itself or from JavaScript as an AJAX call.

It all depends upon which definition of the overused and overloaded buzzword “API” you’re using in your question. Do you need to use an HTTP request with a JSON payload matching some predefined schema? No. But in the more general sense, all URLs are, by definition, an API.

So to summarize an example scenarion. I want to program a login with django. For the frontend I need html, css and javascript for the username and password input. I then pass this data to the backend (Django) with AJAX calls and this logs me in. Would that be correct?

You can do it this way, yes.

Just keep in mind and never lose site of the fact that “an AJAX call” is a request, like any other request being made by a browser. A request from a browser results in a Django view being called. That view will return a response.

1 Like

Is Ajax (Jquery) a package that I need to import? If so, how? Or is it implemented by default in my Django project?

Clarification: AJAX is a name for a set of techniques used to update pages in a browser without doing a full refresh. See Ajax (programming) - Wikipedia

The jQuery library is a JavaScript library that (among other things) provide some easy-to-use functions for implementing AJAX functionality in your pages.