Django TwitterCard

Twitter Cards App for Django >= 1.4

Twitter Cards App for Django >= 1.4

Adds HTML Meta tags for Twitter Card support.

Installation

pip install -e git+git://github.com/npp/django-twittercard.git#egg=twittercard

Upgrade

pip install -U -e git+git://github.com/npp/django-twittercard.git#egg=twittercard

Usage

Optional Configuration

  1. Add twittercard to your settings.py INSTALLED_APPS list
  2. There are a few configuration options to twittercard that can be placed in an OPTIONAL dictionary called TWITTERCARD_CONFIG in settings.py. Refer to the Twitter Card Docs for help regarding card and content attribution.
TWITTERCARD_CONFIG = {
    'SITE': '@foo',
    'SITE_ID': 'foo',
    'CREATOR': '@bar',
    'CREATOR_ID': 'bar'
}

Loading Template Tags

  1. Load the twittercard custom tags
  2. Call the twittercard_summary or twittercard_photo tag, passing in the appropriate parameters
{% load twittercard %}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Django TwitterCard Example</title>
        {% twittercard_summary title="Foo" description="Bar" %}
    </head>
    <body></body>
</html>

The result, including the use of the TWITTERCARD_CONFIG options defined above, would be:

<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@foo">
<meta name="twitter:site:id" content="foo">
<meta name="twitter:creator" content="@bar">
<meta name="twitter:creator:id" content="bar">
<meta name="twitter:url" content="http://url.tld/sub/">
<meta name="twitter:title" content="Foo"/>
<meta name="twitter:description" content="Bar">

Summary TwitterCard

The summary card can be used for many kinds of web content, from blog posts and news articles, to products and restaurants.

{% twittercard_summary site="" site_id="" creator="" creator_id="" url="" title="" description="" image="" %}

Photo TwitterCard

The photo card puts the image front and center in the Tweet.

{% twittercard_photo site="" site_id="" creator="" creator_id="" title="" description="" image="" image_width="" image_height="" %}

Player TwitterCard

Currently not supported in django-twittercard. The player card is for interactive media experiences like videos, music players, and live streaming events.

NOTE: If any required fields are omitted, the card may not be shown in the Tweet.

TODO