[Answered ]-DjangoRestFramework – How do I customize the frontend?

2👍

First off, there are some things to make Django Rest Framework play better with angular. Until I decided to try out ember, I was working through this utorial. To try to provide a useful example for your question:

  1. Typically you want to put your DjangoRestFramework REST Api in something like /api.

  2. If you’re doing the seemingly ubiquitiious single page application, you can then have index.html get served up as a template (i.e. just have your default home view be a TemplateView with index.html as the template)

  3. You would then have your angular html templates and your angular/jquery/etc. javsascripts and your css files as normal static files. NB that you generally don’t want to have django templates generate angular code. First off, it makes things much more of a pain to debug, and secondly, the default angular and django template syntax use the same <% characters meaning you have to be careful to make sure one doesn’t try to interpret the others templating code.

When you load http://yourserver/, this will bring up the index.html page which then pulls down angular stuff, which then starts making RESTful calls to your REST api to generate the data. Note that you can start mixing in stuff to use Django forms etc., but I’d recommend keeping it simple and then reading the linked article (or another) once you have the basics going.

👤Foon

Leave a comment