settings.py, a management
command uploads the template, and a view returns the finished image.
Guide an agent through a SudoMock render in Django.
Prerequisites
- A Django project with an app you can add a view and a command to. The app is
called
mockupsbelow. - Python 3.9 or later, which the client library requires.
- An API key. Keys start with
sm_and travel in thex-api-keyheader. See API keys. - A public URL to the PSD you want to render, and a public URL to the artwork that goes into it.
Guide
1
Install the client
2
Put the key in settings
Three values belong in the environment: the key, and the two uuids the next
step prints. Reading them with Build the client once and import it where you need it. It reads
os.environ means a missing value stops the
project at startup rather than on the first render.SUDOMOCK_API_KEY by itself when no key is passed, but taking it from
settings keeps every secret on one page.3
Upload the template once
A PSD is uploaded once and rendered many times, so this belongs in a
management command rather than in request handling.Run it:Those two uuids are the
SUDOMOCK_MOCKUP_UUID and SUDOMOCK_SMART_OBJECT
values from the previous step.4
Render from a view
The view takes an artwork URL, fills the smart object with it, and answers
with the rendered image.
csrf_exempt is there because this route is called by your own backend. A
route a browser form posts to keeps the token instead.5
Call it and read the answer
render.url. One render answers with one composited image, so
render.print_files carries a single entry and render.url is the shortcut
to it.A failure answers with the code the API returned:A render holds the request open while it runs. Pass
is_async=True to get a
job id back at once and let a webhook tell you when the image is ready.Next steps
SDKs
Every resource the Python client exposes, and the Node one.
Errors
Each
error_code, and which statuses are worth retrying.Webhooks
Let a finished render call your Django route back.