Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install django-twitter-tag

How to install django-twitter-tag

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install django-twitter-tag
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
1.2 Available View build log
Linux (32-bit)
1.2 Available View build log
Linux (64-bit)
1.2 Available View build log
1.2 Available View build log
Lastest release
version 1.2 on May 14th, 2013
https://secure.travis-ci.org/coagulant/django-twitter-tag.png?branch=dev https://coveralls.io/repos/coagulant/django-twitter-tag/badge.png?branch=dev

A django template tag to display user's recent tweets / search results. Version 1.0 uses Twitter API 1.1.

Basic features are limiting numbers of displayed tweets, filtering out replies and retweets. Library exposes each tweet json in template, adding extra attributes: html and datetime. First one makes urls, hashtags or twitter usernames clickable, juts like you expect them to be. Last one provides python datetime object to ease output in templates. Urs are expanded by default. Library handles twitter exceptions gracefully, returning last successful response.


  • Load tag in your template like this:

    {% load twitter_tag %}
  • Get user's (futurecolors in example) most recent tweets and store them in tweets variable:

    {% get_tweets for "futurecolors" as tweets %}
  • Now you have a list of tweets in your template context, which you can iterate over like this:

    {% for tweet in tweets %}
        <li>{{ tweet.html|safe }}</li>
    {% endfor %}

See how it looks like on our site.


This app works with python 2.6, 2.7 and 3.3, Django 1.3-1.5b2.

Recommended way to install is pip:

pip install django-twitter-tag

Add twitter_tag to INSTALLED_APPS in settings.py:



Twitter API 1.1 requires authentication for every request you make, so you have to provide some credentials for oauth dance to work. First, create an application, second, request access token on newly created app page. The process of obtaining a token is explained in detail in docs.

Here is an example of how your config might look like:

# settings.py
# Make sure to replace with your own values, theses are just made up

# Your access token: Access token
# Your access token: Access token secret
TWITTER_OAUTH_SECRET = 'hi1UiXm8rF4essN3HlaqMz7GoUvy3e4DsVkBAVsg4M'
# OAuth settings: Consumer key
# OAuth settings: Consumer secret

For best performance you should set up django cache framework. Cache is used both internally to store last successful json response and externally (see Caching below).


You can specify number of tweets to show:

{% get_tweets for "futurecolors" as tweets limit 10 %}

To filter out tweet replies (that start with @ char):

{% get_tweets for "futurecolors" as tweets exclude "replies" %}

To ignore native retweets:

{% get_tweets for "futurecolors" as tweets exclude "retweets" %}

Or everything from above together:

{% get_tweets for "futurecolors" as tweets exclude "replies, retweets" limit 10 %}

Search tag (experimental)

You can search for tweets:

{% search_tweets for "python 3" as tweets limit 5 %}

Search api arguments are supported via key=value pairs:

{% search_tweets for "python 3" as tweets lang='eu' result_type='popular' %}

Relevant API docs for search.


It's strongly advised to use template caching framework to reduce the amount of twitter API calls and avoid reaching rate limit (currently, 180 reqs in 15 minutes):

{% load twitter_tag cache %}
{% cache 60 my_tweets %}
{% get_tweets for "futurecolors" as tweets exclude "retweets" %}
{% endcache %}


Tweet's properties

get_tweets returns a list of tweets into context. Each tweets is a json dict, that has exactly the same attrubutes, as stated in API 1.1 docs, describing tweet json. Tweet's created timestamp is converted to python object and is available in templates:

{{ tweet.datetime|date:"D d M Y" }}
Tweet's html

Tweet also has extra html property, which contains tweet, formatted for html output with all needed links. Note, Twitter has guidelines for developers on how embeded tweets should look like.

Exception handling

Any Twitter API exceptions like 'Over capacity' are silenced and logged. Django cache is used internally to store last successful response in case twitter is down.


To install development version, use pip install django-twitter-tag==dev



DJANGO_SETTINGS_MODULE = twitter_tag.test_settings python setup.py test

Subscribe to package updates

Last updated May 14th, 2013

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.