<commit_before>Installation and Usage
======================

For a working implementation, you can view the `example project`_ on Github.

Install django-hitcount::

    pip install django-hitcount

Settings.py
-----------

Add django-hitcount to your ``INSTALLED_APPS``, enable ``SESSION_SAVE_EVERY_REQUEST``::

    # settings.py

    INSTALLED_APPS = (
        ...
        'hitcount'
    )

    # needed for django-hitcount to function properly
    SESSION_SAVE_EVERY_REQUEST = True

Urls.py
-------
In your ``urls.py`` file add the following::

    # urls.py
    urlpatterns = patterns('',
        ...
        url(r'hitcount/', include('hitcount.urls', namespace='hitcount')),
    )

View the :doc:`additional settings section </settings>` for more information.

Template Magic
--------------

Django-Hitcount can utilize Javascript out-of-the-box to record the ``Hits`` to an object (be it a blog post, poll, etc).  There is a `jQuery implementation`_ included with the app though you could write your own implementation, or copy-paste the one included, easily enough.

Start by loading hitcount tags on the desired templates::

    {% load hitcount_tags %}

Recording a Hit
^^^^^^^^^^^^^^^

If you want to use the `jQuery implementation`_ in your project, you can add the Javascript file to your template like so::

    {% load staticfiles %}
    <script src="{% static 'hitcount/hitcount-jquery.js' %}"></script>

Then, on your object detail page (blog, page, poll, etc) you inject the needed javascript variables::

    # use default insertion method for hitcount-jquery.js:
    {% insert_hit_count_js_variables for object %}

    # or you can use a template variable to inject as you see fit
    {% get_hit_count_js_variables for object as hitcount %}
    ({ hitcount.ajax_url }}
    {{ hitcount.pk }}

Displaying Hit Information
^^^^^^^^^^^^^^^^^^^^^^^^^^

You can retrieve the number of hits for an object many different ways::

    # Return total hits for an object:
    {% get_hit_count for [object] %}
<commit_msg>include jQuery source in example documentation<commit_after>Installation and Usage
======================

For a working implementation, you can view the `example project`_ on Github.

Install django-hitcount::

    pip install django-hitcount

Settings.py
-----------

Add django-hitcount to your ``INSTALLED_APPS``, enable ``SESSION_SAVE_EVERY_REQUEST``::

    # settings.py

    INSTALLED_APPS = (
        ...
        'hitcount'
    )

    # needed for django-hitcount to function properly
    SESSION_SAVE_EVERY_REQUEST = True

Urls.py
-------
In your ``urls.py`` file add the following::

    # urls.py
    urlpatterns = patterns('',
        ...
        url(r'hitcount/', include('hitcount.urls', namespace='hitcount')),
    )

View the :doc:`additional settings section </settings>` for more information.

Template Magic
--------------

Django-hitcount comes packaged with a `jQuery implementation`_ that works out-of-the-box to record the ``Hits`` to an object (be it a blog post, poll, etc).  To use the `jQuery implementation`_ you can either include the app's script file (as the documentation below shows) or to copy-paste the script into your own jQuery code.  Of course: you could also implement this without relying on jQuery.

Start by loading hitcount tags on the desired templates::

    {% load hitcount_tags %}

Recording a Hit
^^^^^^^^^^^^^^^

If you want to use the `jQuery implementation`_ in your project, you can add the Javascript file to your template like so::

    {% load staticfiles %}
    <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="{% static 'hitcount/hitcount-jquery.js' %}"></script>

Then, on your object detail page (blog, page, poll, etc) you inject the needed javascript variables::

    # use default insertion method for hitcount-jquery.js:
    {% insert_hit_count_js_variables for object %}

    # or you can use a template variable to inject as you see fit
    {% get_hit_count_js_variables for object as hitcount %}
    ({ hitcount.ajax_url }}
    {{ hitcount.pk }}

Displaying Hit Information
^^^^^^^^^^^^^^^^^^^^^^^^^^

You can retrieve the number of hits for an object many different ways::

    # Return total hits for an object:
    {% get_hit_count for [object] %}

{'fraction_non_alphanumeric': 0.13020102851799906, 'fraction_numerical': 0.0009350163627863488, 'mean_word_length': 3.457291666666667, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1419244', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1166, 'n_words': 466}