4
votes

Many third-party website tracking tools and widgets (e.g. Google Analytics, Piwik) require you to copy-and-paste Javascript code into the bottom of your site, right before the closing body tag.

If your website is Django based, what's the standard way of adding this type of code to to the site?

Do you:

  • paste it directly into base.html
  • create a {% block extra_js %}{% endblock %} right before the closing body tag in base.html and stick it in there and/or another template
  • create a new Django app (assuming there's no existing one yet or none that meets your needs)
  • or do something else?

And if you're a consultant dealing with inexperienced clients and you do option 3, do you advise your clients to take the same approach when they're adding to the project code themselves?

3

3 Answers

2
votes

Directly into base.html if the code is the same for all.

If necessary, wrap it in a block tag so that you can override (to remove or replace) in templates that inherit the base.html.

2
votes

Recommended to use EXISTING APPS or CREATE a new APP.

say for google analytics i will use http://code.google.com/p/django-google-analytics/

This way is easy for Maintaining the App.

0
votes

A separate app is a another overhead.

If you want to use it on all pages, follow your point 1.

If you don't want that in all pages, put that in in a block and inherit wherever necessary.