1

Ok, so basically what is happening is I have a search input on my index page. The user types something in the search input, and that is sent to the Django REST api which returns the data in JSON format. I can loop through that results array using Angular ng-repeat. But my question is: is there a way to send that request to another django view and have django return the values using a for loop and a template that I already created?

( I am trying to avoid recreating the template specifically for Angular because that would be repetitive)

Any suggestions, or help on this comes much appreciated. Thank you in advance for taking the time to help me. All the best.

1 Answer 1

1

It depends on the architecture of your application.

If you are building your client as a single page web application using Angular & your business logic is served using the Django REST API in JSON/XML format. Then rendering of the view should be the responsibility of the client side code.

As per me whatever you are doing looks perfectly okay. I don't see any redundancy of the templates in this architecture.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi...Thank you for your answer. I appreciate it. The redundancy that I am concerned about is that I have a django template called stores.html...this includes a for loop that shows a list of results depending on pre-configured criteria. Then in the search page, the user provides that criteria and I parse it using angular to display those results. At that point I have to add that template again, but in an angular format... I hope you know that I am grateful for your response. Best Jon
My suggestion would be to get rid of stores.html template from Django app and create a GET method on /stores and return stores collection in JSON. Move the stores.html presentation code to client side and render the html. Currently, you are mixing design here where some content is served using Django Views (Html) and some is served using REST API. Instead you should serve all your application data using REST APIs and Use client side html templates (like Jade, Stylus or Handlebars) to inject the data in templates and render.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.