Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render Django formsets with AngularJS?

I want to move some parts of a main template into partials which shall not need django rendering (i.e. pure html/js) and use them in a ng-view in the main template.

However, the partials have Django formsets (using crispy) in them i.e useless without Django rendering.

Moreover, I do not want to write the complete formset HTML by hand.

How can I do this?

like image 867
JV. Avatar asked Aug 23 '14 06:08

JV.


2 Answers

Maybe you have a less or sass file too. This file, like your form, it's unusable without preprocessing.

Review code from https://www.djangopackages.com/grids/g/asset-managers/ for inspiration and look at https://docs.djangoproject.com/en/dev/howto/static-files/ to learn how to do it.

Hard part is not do it because its easy make a static finder. Hard part is do it in development staging in a transparent way.

like image 160
lasizoillo Avatar answered Sep 28 '22 10:09

lasizoillo


You can request your partials from the server and put them into the $templateCache yourself using the filename as a key.

This way, when a partial .hmtl file is request, it will get the django rendered HTML.

$http.get('myForm.html', {cache:$templateCache});

You'll want to eagerly load these partial templates, as if the partial template is not in the cache, then it'll request the static html.

Hope this helps

like image 25
leon.io Avatar answered Sep 28 '22 09:09

leon.io