4 ms·
How so? Say the backend developer coded a bunch of Django views where they output json data. They say "Job done. There are API endpoints for everything now.".
by ArtTimeInvestor 5y ago
How so?
Say the backend developer coded a bunch of Django views where they output json data. They say "Job done. There are API endpoints for everything now.".
Now how does the frontend developer bring their templates into play so the json gets rendered "on the server side"?
- tyingq 5y agoIf you were using Django and rendering server side, then I don't imagine you would bother with a REST api layer. But, assuming the the data was already in some REST/JSON api, you would have a Django template filter that used json.loads(), right?
- ArtTimeInvestor 5y agoEither way - how does the front end developer get into play? In a setup where the frontend is doing the rendering, you can give the frontend developer access to a directory with static assets that get output to the browser verbatim. How do you give them the ability to "have a Django template filter" without them having the ability to mess with the rest of the backend? Or do you set up a second server that talks to the APIs of the first server?
- tyingq 5y agoI'm not in a Django shop, but I assume these problems exist anyway. Front-end developers probably also want access to templates, images and css that sit on a server. A template filter would be fairly static though, just converting json into python objects. How to give them access to the Django template itself would be the thing you would want to solve. Node.js seems to have considered some of this, since it's more common to co-mingle front/back end.
- ArtTimeInvestor 5y agoI am also not in a Django shop. But I don't think Django templates are safe in a way that they protect the backend from a clueless or malicious frontend developer. Even if they were, you would have to take great care that you do not expose dangerous functionality. So "give them access to the Django template itself" is not enough. You would have to have a whole security concept around it. And that is not enough. How does the fronted dev create routes? How do they create views, which are the glue between the DB and the templates? Node.js is a runtime, not a framework. It does not have routes, views or templates at all. So that comparison makes no sense. No matter which backend framework you choose - you will have a lot more work to bring the frontend dev into the game if you do backend rendering. Please be aware that I am not against backend rendering. I indeed think that backend rendering is the better approach! I just explain here why there is some appeal to developers to write the backend as an API and do the rendering on the frontend.
- fwip 5y agoDjango templates intentionally provide greatly limited functionality compared to full-python. The idea is that you prepare the needed data in the "view," and then the template should be relatively dumb. If the template is causing any database/backend requests while rendering, that's generally a sign that you haven't put enough information into your view layer.
- travisjungroth 5y agoBy making Django templates and rendering them with the view the backend dev created. Django's original architecture handles this exact separation of concerns. A view creates a context dictionary (which is equivalent to a JSON response) and then the template is rendered with the context before being returned with the response to the client. https://docs.djangoproject.com/en/3.2/ref/class-based-views/base/#templateview https://docs.djangoproject.com/en/3.2/ref/class-based-views/... This pattern seems to have declined in popularity, but it can really win in speed and simplicity over a frontend/API split.