Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Web pages capture using Django & CasperJS

branch: master

django-screamshot is a very naive implementation of Web pages capture with CasperJS (aaAAaah!, phantomjs:))

(See the issues pages for more details about what remains to be done.)

Checkout screamshotter, the simplest Django project powered by django-screamshot.


First make sure you have the casperjs command in your PATH, using related installation instructions.

Then install the egg :

pip install django-screamshot


  • Add screamshot to your INSTALLED_APPS

As a screenshot Web API

Add it to your project URLs :

urlpatterns = patterns('',
    url(r'^capture/$',  include('screamshot.urls', namespace='screamshot', app_name='screamshot')),

You can then obtain a screenshot using the following GET parameters :

The website URL to capture. This can be a fully qualified URL, or the name of a URL to be reversed in your Django project. Note: do not forget to encode the url.
CSS3 selector. It will restrict the screenshot to the selected element.
HTTP method to be used (default: GET)
Viewport width (default: 1400)
Viewport height (default: 900)
HTTP data to be posted (default: {})
CSS3 selector. The screenshot will be performed only once this selector is satisfied. Typical usage: if your page contains a heavy javascript processing, you can add a CSS class on an element when the processing is finished to make sure the screenshot will get the page properly rendered.
If render=html, it will return an HTML page containing the image and where the print diaplo box will be automatically opened.
Resize image (width x height, e.g: 500x500), need install PIL or Pillow.
If true, then resulting image is cropped to match specified size.

For example : http://server/capture/?url=

As a template tag

You can include screenshots in your pages using a template tag. It will perform the capture and return the base64 version of the resulting image.

This is very useful if you don't want to expose the capture API publicly.

{% base64capture URL SELECTOR %}

For example, in a SVG template :

{% load screamshot %}

   xlink:href="data:{% base64capture "company:map" "#map" %}"
   width="640" />

If you run the capture server on a different instance, you can specify the root url for reversing (default is local) :


Customizing the page rendering

The CasperJS script appends the screamshot CSS class on the body element. You can easily customize the rendering for printing using this CSS marker in your CSS stylesheet:

.screamshot #navigation {
  display: none;
.screamshot #main {
  margin: 2em;

Capture views with authentication

You can use Basic HTTP authentication in your Django project, create a dedicated user for screenshots and capture the full URL with credentials (http://user:password@host/page/).

Alternatively, you can use a specific view decorator.

Define the authorized IP to capture your pages in your settings :


And use the provided decorator :

from screamshot.decorators import login_required_capturable

def your_view(request):

CasperJS command and CLI arguments

By default, we look for thr CasperJS binary in the PATH environment variable (like which), but you can bypass this:

    'CASPERJS_CMD': '/home/you/Downloads/apps/capserjs',
You can also specify PhantomJS/CasperJS extra-args, such as
--disk-cache=true with the CLI_ARGS setting :
    'CLI_ARGS': ['--disk-cache=true', '--max-disk-cache-size=30000']

See related documentation on PhantomJS and CasperJS homepages.

Notes about runserver

If you want to test it using runserver, you won't be able to capture pages coming from the same instance.

Run it twice (on two ports) and configure CAPTURE_ROOT_URL.




  • Lesser GNU Public License
Something went wrong with that request. Please try again.