Skip to main content

django-easy-instagram

A Django application that provides a template tag for displaying content from a public Instagram profile. Has ability to cache files locally.

This was originally derived from Marco Pompili's version, but has now been largely rewritten.

Requirements

Installation

Install Django with your favourite Linux packaging system or you can use pip for installing python packages, if Django is not an official package for your distribution:

pip install django

Use pip to install Django Easy Instagram:

pip install django-easy-instagram

Pip should take care of the package dependencies for Django Easy Instagram.

Configuration

Add the application to INSTALLED_APPS:

  INSTALLED_APPS = (
    ...
    'sorl.thumbnail', # required for thumbnail support
    'django_easy_instagram',)

Rebuild your application database, this command depends on which version of Django you are using.

Run your migations:

python manage.py makemigrations django_easy_instagram
python manage.py migrate

Usage

You can use recent_media (containing 10-12 recent entries) like this:

<!DOCTYPE html>

{% load instagram_client %}

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{ instagram_profile_name|capfirst }} Instagram feed</title>
</head>
<body>
<h1>{{ instagram_profile_name|capfirst }} Instagram Feed</h1>
<div id="django_recent_media_wall">
    {% instagram_user_recent_media instagram_profile_name %}
    {% for media in recent_media %}
        <div class="django_easy_instagram_media_wall_item">
            <a href="//instagram.com/p/{{ media.shortcode }}" target="_blank">
                <img src="{{ media.thumbnail_src }}"/>
                <span>{{ media.description }}</span>
            </a>
        </div>
    {% endfor %}
</div>
<p>Got from instagram</p>
</body>
</html>

Resizing and Caching Images

You are able to resize images, which will also mean they are cached locally rather than being loaded from Instagram's servers.

To enable this, ensure you have sorl.thumbnail in the INSTALLED_APPS, and that you have setup Django caching.

In order for requests to Instagram to work properly, you will need to ensure you set the sorl.thumbail setting:

THUMBNAIL_REMOVE_URL_ARGS = False

You can then use the local_cache template filter and specify a size:

{% for media in recent_media %}
...
<img src="{{ media.thumbnail_src|local_cache:'332x332' }}"/>
...
{% endfor %}

The images will be saved locally in a cache.

By default images will be resized and saved at 80% JPG quality, to override this you can use this setting in your Django settings file:

INSTAGRAM_CACHE_QUALITY = 90

Settings

  • INSTAGRAM_PROFILE - the Instagram username to fetch, used when no username is passed to the template tag
  • INSTAGRAM_UA - overrides the user agent sent in the request
  • INSTAGRAM_PROXY - provide a URL for an HTTP proxy

The library will automatically retry up to 3 times if it encounters a non-200 response.

Thanks

The original version of this was built by Marco Pompili available here - abandoned. I've sinced rewritten it to work with Instagram APIs rather than via scraping.

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_easy_instagram-1.0.6-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file django_easy_instagram-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_easy_instagram-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 abe21e2cb9757e5e18ff915cf59bfed09c30236eec33cbdf1c8eb217d4f4f746
MD5 3502e5cc0a3d97f5e6a72fde021dbfe9
BLAKE2b-256 df49e52786bd25c82326c320946bfa7e957041674d2e3fd5e8090c9902e7a269

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.6 This release

1 file

1.0.5

1 file

1.0.4

2 files

1.0.3

1 file

1.0.2

1 file

1.0.1

2 files

1.0.0

2 files

0.3.4

1 file

0.3.3

1 file

0.3.2

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page