1

I am new to developing a website and because of my familiarity with Python and considering the complexity of the website, I chose Django.

I want to know the best practice for developing a template through the Django framework. My question is two-fold.

  1. Is it best to have a bunch of for loops / if statements in the template using template tags and other features of Django?
  2. Or is it passing the variables from Django to Javascript through JSON and then loading the page asynchronously?

For the first, I found the following merits: its fairly easy. I know what I want, I code the loops and I get the result that I expect. Plus giving IDs / names to HTML tags is super simple. Inline scripting also becomes simple, but I personally dont like it. But as objects start to get high in number, page load speed suffers.

For the second, and I am very new to this, the ease is gone. There is, I feel, another hoop to jump through Javascript, with JSON parsing and then the actual modeling.

If not either first or second, may be there is a balance between the two? All help is appreciated.

1
  • you can use the loop in your template, if there too many data use pagination Commented Jun 26, 2020 at 2:43

1 Answer 1

1

If i got your question correctly then i think the answer is AJAX i.e, using the same page to load different content.You don't have to go to another page but on the same page, setting some links, you can pull newer data without loading a new page. Hope this helped you!

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

2 Comments

Thank you, @Irfan. What is best practice, however? Is the industry inclined towards one way or the other?
As you were having the issue regarding loading speed while loading the content, thus i think AJAX is a good practice.

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.