1

I'm trying to move a Django backend to a RESTful API in order to let a mobile app access the backend. I'm using Django REST framework for this.

So if I serialize all my models and objects and render in JSON (for mobile app), how do I render the serialized models and objects in my django templates (for website)?

I realize there are many ways to render (TemplateHTMLRenderer, JSONRenderer, etc.). But once I serialize, I'm not able to render using TemplateHTMLRenderer.

So should I just serialize and render in JSON for mobile app and just render using TemplateHTMLRenderer if it's a regular request (website)? So everything is just if-else? What strategies do people usually use to move to a RESTful API? How do I go about this?

eager_coder
  • 47
  • 1
  • 8
  • Usually you would have javascript making ajax calls to your rest endpoint and doing the rendering. If you want to render everything on the server side inside a template then there is no point in serializing anything. You need to either create a different endpoint for template rendering, or pass some url parameters letting server know that instead of serializing(or "rendering") to json it should render to a template. – serg Sep 15 '16 at 03:05
  • What you normally would do is getting the JSON via Ajax in your mobile app. The mobile app is then responsible for the rendering to HTML and not the Django or Django Rest Framework. – DanEEStar Sep 15 '16 at 15:37

0 Answers0