Is there a standard way to add “copy and paste” Javascript code to a Django project?

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

If your site is based on Django, what is the standard way to add this type of code to the site?

You:

  • paste it directly into base.html
  • create {% block extra_js%} {% endblock%} right before the closing body tag in the base.html file and paste it there and / or another template
  • create a new Django application (assuming there isn’t one, not one that suits your needs)
  • or do something else?

And if you are a consultant with inexperienced clients, and you are doing option 3, do you advise your clients to follow the same approach when they add the project code themselves?

+4
source share
3 answers

Directly in base.html if the code is the same for everyone.

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

+2
source

It is recommended to use EXISTING APPLICATIONS or CREATE a new APP.

let's say for google analytics I will use http://code.google.com/p/django-google-analytics/

This method is simplified to support the application.

+2
source

A separate application is another service information.

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

If you do not want all pages to put this in a block and inherit where necessary.

0
source

Source: https://habr.com/ru/post/1342576/


All Articles