Is it possible to use REST API on Django template ?

913 views
Skip to first unread message

Aman Modi

unread,
Nov 25, 2020, 9:19:58 AM11/25/20
to Django users


Hello Django lovers.

I want to use REST API  on Django template but i have no idea how can i do that.
I want to use same API on android app and Django template.

Any suggestion .

Thanks and regard
Aman Modi

Omkar Parab

unread,
Nov 25, 2020, 9:37:47 AM11/25/20
to django...@googlegroups.com
Creating REST API in Django is similar to any app on Django. All you need to do is, install the djangorestframework library, and serialize your models. 

On Wed, Nov 25, 2020, 7:48 PM Aman Modi <amanmo...@gmail.com> wrote:


Hello Django lovers.

I want to use REST API  on the Django template but I have no idea how can I do that.
I want to use the same API on the android app and the Django template.

Any suggestion.

Thanks and regard
Aman Modi

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/99c6d921-9ea7-4f3b-9d69-03b06fbbd5d8n%40googlegroups.com.

Devender Kumar

unread,
Nov 25, 2020, 10:50:53 AM11/25/20
to django...@googlegroups.com
Use ajax with django rest framework 

Farai M

unread,
Nov 25, 2020, 11:21:56 AM11/25/20
to django...@googlegroups.com
Very possible you can create urls for API with the rest framework then create other  urls for your templates .Just install the django rest framework you are good to go.

Kris A. Stern

unread,
Nov 25, 2020, 11:48:29 AM11/25/20
to django...@googlegroups.com

Venu Gopal

unread,
Nov 26, 2020, 11:04:27 PM11/26/20
to django...@googlegroups.com
Yes, it is possible. Below is the documentation. we will use serialization to get a django rest API.

Aman Modi

unread,
Nov 29, 2020, 1:25:35 AM11/29/20
to Django users
I know how to create API but i just want to know how to use in Django template.

RANGA BHARATH JINKA

unread,
Nov 29, 2020, 2:06:44 AM11/29/20
to django...@googlegroups.com
Hi 
Use JavaScript or jQuery to call APIs in frontend of Django template.
You can use fetch API using vanilla JavaScript.
You can perform all CRUD operations.
All the best 👍

sree e

unread,
Nov 29, 2020, 12:30:33 PM11/29/20
to Django users

Hi 
And go through "api" app , where you will find adding the api in easy way.

Liu Zheng

unread,
Nov 30, 2020, 9:04:44 PM11/30/20
to django...@googlegroups.com
Hi,

Guys earlier have provided useful links for consuming APIs. Just want to emphasize some concepts between server-side and client-side codes.
A django template is rendered into a page on the server side. That means, the server does the work and prepares the html content before sending it to the browser. In theory, you can call APIs when rendering the templates on the server side, but it's almost never a good idea. APIs are designed to be consumed by clients. The django templates should contain the relevant  javascripts (using ajax). These javascripts are not executed when the server renders the templates. They are sent as they are to the client, and are executed automatically by the browser. If the javascript calls API, the browser will come back to your server (this time, to the rest api endpoints, instead of the template rendering endpoints) and consume your API.

Hope it helps.

Best
Zheng

Kris A. Stern

unread,
Nov 30, 2020, 9:09:41 PM11/30/20
to django...@googlegroups.com
Hey, 

Guess you are making some baseless assumptions about the so-called templates... Can the original poster of the question please clarify what you really meant before we get more and more confused? 

K.S. 

Suhaib Ali

unread,
Dec 3, 2020, 3:37:24 AM12/3/20
to django...@googlegroups.com
you can use jquery to fetch api calls 

Reply all
Reply to author
Forward
0 new messages