Skip to main content

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

For now it’s recommended to install via pip:

pip install -e git+https://github.com/futurecolors/django-twitter-tag#egg=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 }}</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" %}

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

If DEBUG==True any Twitter API exceptions like ‘Over capacity’ are raised and propagated, otherwise the’re silenced.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-twitter-tag-0.2.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

django-twitter-tag-0.2.0.linux-x86_64.exe (70.4 kB view details)

Uploaded Source

File details

Details for the file django-twitter-tag-0.2.0.tar.gz.

File metadata

File hashes

Hashes for django-twitter-tag-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f708f313c83eb00070883c113cc151fed497a3759ae6423439c5dd2c54c6ccf2
MD5 fbf03ba2e80f2efd86a8020356998a5d
BLAKE2b-256 e72e35ccf276e2455dce15fe85803eb64191d97a851ebe30bc2b1b49a131070e

See more details on using hashes here.

File details

Details for the file django-twitter-tag-0.2.0.linux-x86_64.exe.

File metadata

File hashes

Hashes for django-twitter-tag-0.2.0.linux-x86_64.exe
Algorithm Hash digest
SHA256 32ed49183aaa8b2f015bb4ed2bf6f26f19428d4f6494d339b0ac8f66cb855d5b
MD5 a90c15926f662eacab7be9522b6baceb
BLAKE2b-256 280767cbe35df636dd4475dedf3c1dc1b8ea21d3ea2cf7d8c37261ef8be4dd98

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page