English subtitles

← Helpful Tips - Web Development

Get Embed Code
2 Languages

Showing Revision 4 created 09/15/2017 by Dejan Trajkovic.

  1. Okay just a couple of helpful tips, to reiterate the one
  2. I just gave you before is, always automatically escape variables when
  3. possible. Not every template language will allow you to do so,
  4. but always give it a look. Jinja certainly allows you do to
  5. so. So in this class you should definitely do that. Next
  6. is, minimize the code that you include in templates. What I've showed
  7. you so far, if statements and for loops. That's about it. Jinja
  8. will allow you to put almost, like arbitrary Python into your templates.
  9. But, you remember the whole reason we're using templates
  10. in the first place is, so we don't have to
  11. have HTML in our code, likewise we don't have code
  12. in our HTML. Because it makes it very difficult to,
  13. to modify, to edit, to debug, all those things.
  14. It's a total pain. So, and of course, the inverse
  15. of this is minimize your HTML in code. I generally,
  16. I have a rule generally, where we have zero HTML
  17. in our code. Even if it's a little one-line thing,
  18. we put it in a template. That way all your HTML
  19. is in one place, all your code is in one place,
  20. and you don't, you're not using the wrong tool for the
  21. job. Which inevitably will bite you down the road as
  22. your projects get more complex. Those are just some things you
  23. know, these aren't hard and fast rules but these are things
  24. that I've found that have served me well over the years.