#Can django directly serve a frontend application that was built using a framework

10 messages · Page 1 of 1 (latest)

grave pond
#

Can it somehow itself, serve say a react or svelte app? I know I can build a rest api using django, serve it on a port, and build a frontend app and serve it on another port communicating over the api with the server, but I want them both to be served by django and be on the same port if possible (I know I can proxy the api address and port so I don't need to specify the port each time I want to call the api, that's beside the point)

tacit iron
#

Yes. build the JS files and serve them as django static files

grave pond
#

Like how? You mean like for react for example I use babel and then serve the result?

tacit iron
#

Yep, build the files so they end in a directory that will be collected using collectstatic then django will serve them as normal

grave pond
#

And that way I won't lose any functionality for the frontend app right? Sorry I haven't done this before, I have a good idea how to approach it but no experience, just making sure

tacit iron
#

At this point I would say try it out. use version control so you can easily revert back to a known state. this is part of learning, experiment and try it out

grave pond
#

Alright, thank you will try it

#

@tacit iron Oh btw (sorry for the tag) I know it's probably dpendant on my usage but generally speaking is that how it's done in production as well or do prople just server them separately?

tacit iron
#

It depends... both are valid, but serving via Django is going to be a simpler deployment strategy

grave pond
#

So I'm not doing something that's uncommon or anything :D