Django gives us the ability to create API’s at a minimum time while preserving the versatility of Python. We will be able to create a simple recipe app that will be ready to use via POSTMAN or any other URL call.
Having an API that performs CRUD seamlessly across the platform is very important. Having a single source of data for various platforms like apps and website is a must at this age and day.
Django gives us the ability to create API’s at a minimum time while preserving the versatility of Python. We can create API’s with a fully functional dashboard within minutes. On top of that, It has a GUI with ADMIN login such as authentication adding users are already inbuilt.
In this article, we will be able to create a simple recipe app that will be ready to use via POSTMAN or any other URL call.
Disclaimer for Details and Actual Documentation. **[DJANGO DOCS**](https://docs.djangoproject.com/en/3.1/topics/)
Things we are gonna need to create the API:
But first, we need to create an isolated virtual environment.
A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated Python virtual environments for them. This is one of the most important tools that most Python developers use.
The following Commands are used to set up and activate.
Create the directory for this environment in any of your preferred drive.
mkdir /C/”your project” cd /C/”project”
Now you are in the Project Directory. Time to set up a virtual environment.
If you are in Python 2 use, even tho it is not preferred.
python -m virtualenv djangoapi
Else if in Python 3, use.
python -m venv djangoapi
Now to activate the virtual environment.
In Windows Source venv/scripts/activate in Mac source bin/activate
You can see the packages installed inside the environment. You can check on that by using** pip freeze. **AS of now, you wouldn’t see any list of packages added.
Next, we install all the dependencies we need. And then you should run pip freeze to see the changes.
pip install Django pip install Djangorestapi
Once you have successfully installed all dependencies it should look like this.
Once We have successfully installed Django, it's time to create our recipe project. Django has made our lives easier by giving a bunch of predefined commands. You can the Start project command to
django-admin.py startproject djangoapiproject
now hit ls to see the directory.
Now our directory for the project has been created.
We can now transfer onto the Text Editor, my preference is Visual Studio Code.
Select your the designated folder in my case which is
Before we can migrate all our dependencies we need to first see whether all of them are listed in settings.py. In my case, rest_framework was to be added.
Now that we have added the applications list, we can now migrate the dependencies.
winpty python manage.py migrate
You will see all of your admin dependencies being migrated into the manage.py
Now from the manage.py file will become the focal point of our project.
To see the changes successfully installed.
python manage.py runserver
You can observe the live project in the following by going on to localhost:8000
Now we are set up to create our very first own API.
Are you looking for experienced, reliable, and qualified Python developers? If yes, you have reached the right place. At **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, our full-stack Python development services...
Looking to build robust, scalable, and dynamic responsive websites and applications in Python? At **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, we constantly endeavor to give you exactly what you need. If you need to...
In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.
After analyzing clients and market requirements, TopDevelopers has come up with the list of the best Python service providers. These top-rated Python developers are widely appreciated for their professionalism in handling diverse projects. When...
APIs can be as simple as 1 endpoint for use by 100s of users or as complex as the AWS APIs with 1000s of endpoints and 100s of thousands of users. Building them can mean spending a couple of hours using a low-code platform or months of work using a multitude of tools. Hosting them can be as simple as using one platform that does everything we need or as complex as setting up and managing ingress control, security, caching, failover, metrics, scaling.