A django template tag to display user's recent tweets.
Project description
A django template tag to display user’s recent tweets.
You can limit number of tweets, filter out replies and retweets. Since the app exposes python-twitter Status model to template context, you can also access any tweet attributes or methods for your needs. You don’t need to parse tweets to make urls, hashtags or twitter usernames clickable, it has been done for you already. Just use tweet’s html attrubute (see example below).
Installation
This app works with python 2.6 and higher, Django 1.3 and higher.
Recommended way to install is pip:
pip install django-twitter-tag
Usage
Add twitter_tag to INSTALLED_APPS in settings.py:
INSTALLED_APPS = (... 'twitter_tag', ... )
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:
<ul> {% for tweet in tweets %} <li>{{ tweet.html|safe }}</li> {% endfor %} </ul>
Examples
You can specify number of tweets to get:
{% get_tweets for "futurecolors" as tweets exclude "replies" limit 10 %}
To filter out tweet replies (that start with @ char):
{% get_tweets for "futurecolors" as tweets exclude "replies" limit 10 %}
To ignore native retweets:
{% get_tweets for "futurecolors" as tweets exclude "retweets" %}
Caching
It’s strongly advised to use template caching framework to reduce the amount of twitter API calls and avoid reaching possible request limit:
{% load twitter_tag cache %} {% cache 3600 my_tweets %} {% get_tweets for "futurecolors" as tweets exclude "retweets" %} ... {% endcache %}
Extra
Tweet’s properties
get_tweets holds a list of Status objects, which represet single user tweet. According to python-twitter API, every status has following attributes, availiable in templates:
status.created_at status.created_at_in_seconds status.favorited status.in_reply_to_screen_name status.in_reply_to_user_id status.in_reply_to_status_id status.truncated status.source status.id status.text status.location status.relative_created_at status.user status.urls status.user_mentions status.hashtags
Tweet’s html
Tweet also has extra status.html property, which contains tweet, formatted for html output with all needed links.
Exception handling
Any Twitter API exceptions like ‘Over capacity’ are silenced and logged.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for django-twitter-tag-0.4.0dev.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 895df58220bcfa23cbf02b19d1c03cd4161125ca8a9169c8130b68e78a98436a |
|
MD5 | 357f2d5a19ac0baf541da58254e3cfbf |
|
BLAKE2b-256 | f395db60d5624120ab615c8c82f84011044232caad5b4294f77ee2a55875cc60 |