I’m new to app development and have been creating a app with flutter UI and creating a backend with django and Mongodb.. How to link this with each other.. I don’t know which file should i write the link code.
I opened flutter app with dependencies with flutter create newapp
and django app.
3
Answers
Hi Nithin i understand your question
Django will be used for the api and mongodb is the non relational database.
You have two options to get data from mongodb to flutter application
Django is a really good framework for web applications.
Nevertheless it is not adapted natively to work with nosql databases like mongodb. See the doc
As you are new to app development, I would advice you to use Mysql with Django, or to change to another framework if you want to keep mongodb. App development is difficult, so if I were you I would try to not add more difficulty in using tools not designed to work together.
If you want to continue with Django, you can use Rest Framework to create an API in order to connect your frontend with your backend.
First of all I don´t recommed to call the database directly from the frontend, you have to develop a backend so you can call it´s endpoints. If you are using backend-as-a-service you´ll have boilerplate in your code and configuration it´s limited.
To connect with the backend you need an Http client to do it (I recommend
dio
), you should have exposed enpoints in your backend so you must create a repository in your flutter app:Add the package in your
pubspec.yaml
Use example, simple CRUD of Task object:
Also I recommed to serialize the objects with the
json_serialization
package. Seehttps://stackoverflow.com/a/77088234/22000646