Home > Enterprise >  Is separating django frontend and backend with API viable?
Is separating django frontend and backend with API viable?

Time:07-01

I'm used to Django and already developed website with a whole Django or with Django API React.

For a side project, I'm thinking about creating a Django project with 2 apps:

  1. Django API 2) Django Front.

I absolutely want to decouple front/back to be able to reuse the API in the future, and I like the view system from Django.

Is my idea making sense?

Edit 1:

To clarify. App 1: Django API serving JSON. App 2: Django App using API calls in the controllers to generate the views.

Edit 2:

I did a proof of concept and it works like a charm. The only drawback is that I have to use Cookies to store the JWT token and maintain the session state, which is not convenient

CodePudding user response:

it is possible, but completely wrong with idea.

  1. How it possible. Wrong version: Try to remember, how we can create integrate test for our view. We Should create client and send request to Django to your view-url with args kwargs querystring e.t.c. In response you have already answer. Try to imagine: part with client - is your Django front, requested part - your backend.

The same works not only in test, you can create request to ask something on the completely other server.

  1. Redis/MemCashed e.t.c. (pattern sender/receiver) Wrong version: The Front Django speaks with Backend through Third part application. It can be faster.

  2. "Pythonic" version. Right in your case: You can create Backend Django part like a library with views as interfaces. Frontend Django part is completely standalone, it import an use interfaces from library, which is your "BackEnd Module".

If you want - you can use "BackEnd Module" everywhere as import, or you can start it as server and ask info per requests.

Completely independent in this case means, you can install "BackEnd Module" without "FrontEnd Module". "FrontEnd Module" can be installed standalone too and it should take from settings, which interfaces should be used as data-source.

I hope, i am right understand your question.

CodePudding user response:

You could definitely separate front and back, remember, django just creates endpoints and consumes them with its own views, you can even use both.

Here is the documentation for django views: https://docs.djangoproject.com/en/4.0/#the-view-layer

You can use a librarie like React as frontend and connect to your api(django app) and use both.

  • Related