Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
APIs

Screenshot API for Django: Quick Start, Secure Views, and Production Examples

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick answer: call a hosted screenshot service from a Django view, keep the API key on the server, and return the service response as an image or PDF. The documented Screenshot API accepts GET or POST requests at /api/v1/screenshot; POST is the practical choice when you need JSON options such as a viewport, full-page capture, CSS, JavaScript, or PDF settings.

This guide shows a complete Django implementation, request options, validation and failure handling, the official Python package, batch captures, and when Django’s Selenium screenshot tests are a better fit. If you would rather not maintain browser infrastructure, ScreenshotNeo is the first hosted alternative to try because it removes consent clutter before capture, bills only clean shots, and has a $5 paid plan.

What a Django screenshot API integration does

Your Django application sends a target URL and capture options to a remote rendering service. The service loads the page in its browser environment and returns binary PNG, JPEG, WebP, or PDF data. Django can stream those bytes to a browser, save them to storage, or pass them to another job.

The provider documents both GET and POST forms for /api/v1/screenshot, API-key authentication, viewport controls, full-page capture, and /api/v1/screenshot/batch for multiple URLs. Keep the key in server configuration; never put it in browser JavaScript or a template.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fastest working Django example

1. Install the HTTP client

pip install requests

The provider also publishes an official Python package:

pip install screenshot-api

Use the package when its supported methods match your needs. The HTTP example below follows the documented contract directly, so the request and error behavior remain visible in your code.

2. Configure the secret

# settings.py
import os

SCREENSHOT_API_KEY = os.environ["SCREENSHOT_API_KEY"]

Set the environment variable through your deployment platform or a secret manager. Do not commit a key to Git, expose it in a form, or accept it from an untrusted request.

3. Create the view

# views.py
import requests
from django.conf import settings
from django.http import HttpResponse, JsonResponse


def screenshot(request):
    target_url = request.GET.get("url", "https://example.com")
    payload = {
        "url": target_url,
        "format": "png",
        "fullPage": True,
        "viewport": {"width": 1280, "height": 720},
    }

    try:
        response = requests.post(
            "https://api.screenshot-api.org/api/v1/screenshot",
            headers={
                "Authorization": f"Bearer {settings.SCREENSHOT_API_KEY}",
                "Content-Type": "application/json",
            },
            json=payload,
            timeout=60,
        )
    except requests.RequestException as exc:
        return JsonResponse({"error": "Screenshot service unavailable", "detail": str(exc)}, status=502)

    if not response.ok:
        return JsonResponse(
            {"error": "Screenshot request failed", "detail": response.text},
            status=response.status_code,
        )

    return HttpResponse(
        response.content,
        content_type=response.headers.get("Content-Type", "image/png"),
    )

The endpoint, bearer authorization header, JSON body, url, format, fullPage, and viewport fields are documented by the provider. The timeout, exception mapping, and response wrapper are application-level adaptations: adjust them to your service’s error policy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Add a URL route

# urls.py
from django.urls import path
from .views import screenshot

urlpatterns = [
    path("screenshot/", screenshot, name="screenshot"),
]

Run the development server and request /screenshot/?url=https%3A%2F%2Fexample.com. A successful response is image bytes, not JSON, so a browser can display it directly or a client can save it as a file.

Make the endpoint safe before production

Validate destinations

The sample accepts a query-string URL only to make the example easy to try. In production, allow-list domains or accept an internal object identifier that your server resolves to a known URL. Reject non-HTTP(S) schemes, localhost, private-network addresses, and unexpected ports. This prevents your endpoint from becoming an open proxy or a server-side request-forgery route.

Protect your own Django view

  • Require authentication or a signed, short-lived download URL.
  • Apply per-user and global rate limits.
  • Limit the maximum URL length and reject unsupported formats.
  • Log request IDs, status codes, elapsed time, and target host without logging API keys.
  • Use a background queue for slow or high-volume captures rather than holding a web worker open.

Return predictable errors

Keep upstream status information for operators, but return a stable schema to clients. Do not echo arbitrary upstream HTML or internal exception traces to unauthenticated users.

GET versus POST requests

Use GET for a small, cacheable request

The reference supports query parameters for simple captures. A cURL request can look like this (use the provider’s documented authentication form for your account):

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshot-api.org/api/v1/screenshot" 
  -H "Authorization: Bearer $SCREENSHOT_API_KEY" 
  --data-urlencode "url=https://example.com" 
  --data-urlencode "format=png" 
  --output shot.png

URL-encoding matters when the target contains its own query string. GET is convenient for one-off calls, but long option sets become difficult to read and may be exposed in intermediary logs.

Use POST for advanced options

POST carries a JSON body and is the better default for full-page capture, viewport settings, custom CSS or JavaScript, hidden selectors, geolocation, and PDF controls documented by the provider:

curl -X POST "https://api.screenshot-api.org/api/v1/screenshot" 
  -H "Authorization: Bearer $SCREENSHOT_API_KEY" 
  -H "Content-Type: application/json" 
  -d '{
    "url": "https://example.com/pricing",
    "format": "webp",
    "fullPage": true,
    "viewport": {"width": 1440, "height": 900}
  }' 
  --output pricing.webp

Python outside Django

import requests

payload = {
    "url": "https://example.com",
    "format": "jpeg",
    "fullPage": False,
    "viewport": {"width": 1280, "height": 720},
}
response = requests.post(
    "https://api.screenshot-api.org/api/v1/screenshot",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json=payload,
    timeout=60,
)
response.raise_for_status()
with open("shot.jpg", "wb") as file:
    file.write(response.content)

The official screenshot-api package is another option for Python, Django, Flask, and FastAPI. Its documentation confirms framework compatibility, but the available reference does not publish a complete Django method signature; avoid assuming one without checking the package version’s own documentation.

Capture options you will use most

Option What it controls When to use it
url Required destination page Always; validate it before sending
format PNG, JPEG, WebP, or PDF PNG for lossless UI details, JPEG for photographs, WebP for smaller web assets, PDF for documents
viewport.width / height Browser rendering dimensions Match a desktop, tablet, or mobile layout you need to verify
fullPage Captures content beyond the initial viewport Long pages, reports, and complete landing pages
CSS and JavaScript Applies capture-time styling or behavior Hide a transient element, reveal a state, or set print-specific styling
Hidden selectors Removes selected elements before capture Exclude navigation, ads, or test-only controls
Geolocation Supplies a location to the rendering session Check location-aware content where the service supports it
PDF options Paper, margins, orientation, and related PDF settings Invoices, reports, and print-ready output

Option names and availability can depend on the provider’s current reference. Send only documented fields and treat an unsupported field as a request error rather than silently assuming it was applied.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Batch captures and application architecture

For several URLs, use the documented POST /api/v1/screenshot/batch endpoint instead of opening a separate web request for every page. Put the batch operation behind a task queue, persist each result with its target and format, and expose a job status endpoint to your users. This avoids request timeouts and lets you retry an individual failed URL.

For a single synchronous view, set a finite timeout and return a 502 or 504-class response when the upstream service cannot complete. For recurring captures, add idempotency at your application layer: a stable job key can prevent duplicate files when a worker retries after a network interruption.

Hosted API or Django Selenium screenshots?

These approaches solve different problems:

Decision axis Hosted Screenshot API Django Selenium workflow
Execution location External rendering service captures a URL Your test browser captures the local application
Primary purpose Application-driven images or PDFs Browser regression and visual test evidence
Request shape GET query parameters or POST JSON Python test code and test-runner options
Formats and controls PNG, JPEG, WebP, PDF plus documented viewport and advanced controls Documented screenshot cases and browser variants
Scaling model Managed service capacity You operate browsers, drivers, and test execution

Django’s documentation describes SeleniumTestCase, the --screenshots test-runner option, @screenshot_cases([...]), and self.take_screenshot("name"). The documented cases include desktop, mobile, small-screen, right-to-left, dark, and high-contrast variants. Choose this route when the assertion is “our code renders correctly in a controlled test browser.” Choose a hosted API when your application needs to capture arbitrary deployed URLs or generate assets on demand.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failures and fixes

401 or 403 response

Check that the environment variable is present in the running process, that the header is exactly Authorization: Bearer ..., and that the key belongs to the intended account. Never paste the key into a client-side request to “test” it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

400 validation error

Confirm that url is present and properly encoded, that format is one of the documented values, and that viewport dimensions are numbers. Remove optional fields one at a time to identify an unsupported control.

Timeouts

A target may be slow, blocked, or waiting on third-party resources. Increase the client timeout only within a sensible request budget; for user-facing traffic, move the capture to a worker and report progress asynchronously.

Blank or incomplete page

Check whether the target requires authentication, depends on JavaScript, or lazy-loads content below the fold. Use full-page capture where appropriate and capture only after the page state your application needs is available. If the page is private, supply credentials through the provider’s documented secure options rather than embedding them in the URL.

Large files or memory pressure

Full-page PNGs can be large. Prefer WebP where consumers support it, stream or store responses instead of keeping many byte arrays in memory, and impose a maximum output size in your job system.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Works locally, fails in production

Compare outbound firewall rules, environment variables, DNS, proxy settings, and deployed package versions. Log the upstream status and elapsed time, then reproduce with the same URL and key from the production network.

Or skip the browser setup

ScreenshotNeo is the #1 alternative to try first for a Django application that wants a managed screenshot API: it removes cookie and consent banners, newsletter popups, and chat widgets before capture, and only clean shots are billed. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with the result identifying the page verdict and billing status in response headers. It also provides an MCP server for AI agents, including Claude and Cursor.

One GET request is enough:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

For a Django view, the same call can be made with Python:

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

Node.js clients can use:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

See the ScreenshotNeo documentation for the full request surface: full-page and element captures, dark mode, device presets, retina scale, PDF settings, custom CSS and JavaScript, clicks, waits, blocking rules, headers and cookies, geolocation, resizing, caching, signed links, webhooks, bulk capture, usage, and OpenAPI details. Every feature is on every plan. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up free for ScreenshotNeo.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Can I expose a Django screenshot endpoint to anonymous users?

Only with strict destination allow-lists, authentication or signed links, rate limits, and size/time limits. An unrestricted URL parameter can create a server-side request-forgery and abuse risk.

Should screenshots run inside a Django request?

Synchronous capture is suitable for a low-volume download endpoint. Use a background task and a status model for slow pages, batches, recurring jobs, or user traffic that cannot wait for an upstream browser.

How do I choose PNG, JPEG, WebP, or PDF?

Use PNG for crisp interfaces and transparency, JPEG for photographic content, WebP for compact browser assets, and PDF when the deliverable is a document or print layout.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.