From old-school Post/Redirect/Get to modern web

56 views
Skip to first unread message

Thomas Güttler

unread,
Aug 29, 2017, 4:15:30 AM8/29/17
to Django REST framework
I use Post/Redirect/Get since several years. I use simple HTML forms (via ModelForm) with a plain old submit-button.

Above pattern works.

But I think the web of the future works different.

Up to now my web application sends html to the web client. I think modern web applications
don't send html, they send data (in json format).

I guess in the future web clients render the (json) data using a library/framework.

For me this client-side rendering is completely new. I have no clue where to start this adventure.

I guess django-rest-framework could help on the server side....

Has anyone hints or practical experience?

BTW, I asked the same question some days ago in the django user group: https://groups.google.com/d/msg/django-users/DXF_jnb5Fow/kGefF8QYCAAJ

Jeremy Stretch

unread,
Aug 29, 2017, 9:17:38 AM8/29/17
to Django REST framework
A common pattern is to have a REST API (like DRF) return JSON-formatted data to the client, and use a front end library to render that data on the page. Here's an example using jQuery to retrieve and render a static JSON file: https://www.sitepoint.com/ajaxjquery-getjson-simple-example/ (In practice, you would replace the static JSON file with a dynamic API).

Hope that helps!

Jeremy

Thomas Güttler

unread,
Aug 30, 2017, 8:28:48 AM8/30/17
to Django REST framework


Am Dienstag, 29. August 2017 15:17:38 UTC+2 schrieb Jeremy Stretch:
A common pattern is to have a REST API (like DRF) return JSON-formatted data to the client, and use a front end library to render that data on the page. Here's an example using jQuery to retrieve and render a static JSON file: https://www.sitepoint.com/ajaxjquery-getjson-simple-example/ (In practice, you would replace the static JSON file with a dynamic API).

Hope that helps!

Jeremy



Thank you Jeremy.

If I go this way (sending data (not HTML) to the web client), then I will miss the great django forms library.

Is there an equivalent which works well with django-rest-framework?

Regards,
  Thomas Güttler

Ian Maurer

unread,
Aug 31, 2017, 7:54:54 AM8/31/17
to Django REST framework
Thomas,

Please read this page:

The serializers in REST framework work very similarly to Django's Form and ModelForm classes. We provide a Serializerclass which gives you a powerful, generic way to control the output of your responses, as well as a ModelSerializer class which provides a useful shortcut for creating serializers that deal with model instances and querysets.

You will also enjoy the browsable HTML interface of DRF that comes for free:

good luck,
Ian

Thomas Güttler

unread,
Aug 31, 2017, 12:07:05 PM8/31/17
to Django REST framework
I am not a student at university any more. I (unfortunately) can't do  programming adventures at the moment.

I won't go this route as long there is no JS-framework which helps me to render HTML forms of the data in the browser which was serialized using django-rest-framework. Of course the next step (from browser back to drf, to db) needs to exist as well.

Strange, that there is no JS-framework which builds a bridge between drf and some other JS-framework (angular, ember, ...)

The only thing I found was this: https://github.com/drf-forms/drf-schema-adapter

Regards,
  Thomas Güttler
Reply all
Reply to author
Forward
0 new messages