Comments (1)
Hey, great question!
As you alluded to, we have a render_template endpoint, though as you alluded to, the rate limit is sufficiently low such that it’s available for testing as opposed to running production workloads.
As for whether you can overcome this rate limit by rendering the email yourself before sending it on your own: yes, though with some caveats.
Klaviyo uses the Django Template Language, though with some customizations. If your template uses standard Django (e.g: just context variables), you should be able to render it using something like the following:
from django import template
from django.template import Context, Template
from django.conf import settings
import django
import json
import datetime
template_file = 'template.html'
context_file = 'context.json'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
},
]
settings.configure(TEMPLATES=TEMPLATES)
django.setup()
register = template.Library()
@register.simple_tag
def current_year():
return datetime.datetime.now().year
with open(template_file, 'r') as f:
template_text = '{% load current_year %}' + f.read()
with open(context_file, 'r') as f:
context_payload = json.load(f)
template = Template(template_text)
context = Context(context_payload)
rendered = template.render(context)
with open('rendered.html', 'w') as f:
f.write(rendered)
Caveat: If your template uses non-standard Django features (e.g: Klaviyo-specific tags, such as {% current_year %}
), you may need to make some modifications (such as above code for registering current_year
as a tag and adding {% load current_year %}
to start of template). We might be using a common extension of the Django template language, though I'll need to look into that. I'll also look into whether there is additional tooling/code samples we can share to cover more cases, maybe a django app that defines all tags.
In the meantime, I’ll link you these 2 guides which you may find helpful.
- https://developers.klaviyo.com/en/docs/django_message_design
- https://help.klaviyo.com/hc/en-us/articles/4408802648731
Please reach out if you run into any further issues, we really value this kind of feedback.
Cheers,
Jon
from klaviyo-api-python.
Related Issues (20)
- How to use "page[size]" parameter? HOT 1
- how to avoid error when making many calls? HOT 1
- No Page Size in "get_profiles" HOT 1
- Missing positional argument "id" even though it is provided HOT 2
- Feature request: Bulk setting/unsetting of user properties HOT 4
- fields[profile] parameter not working HOT 2
- permissions issue with getting lists + campaign audience type (List\Segment) HOT 1
- klaviyo.Templates.get_template return error 500 HOT 3
- Klaviyo API hangs once every 10-20 requests HOT 4
- _from_openapi_data() missing 1 required positional argument: 'name' on create event HOT 2
- _from_openapi_data() missing 1 required positional argument: 'name' on create event HOT 1
- Need basic documentation on how Track and Identify map into this new API HOT 1
- bug in profile unset property functionality HOT 2
- 400 HTTP errors with get_events() per specific metric ids HOT 4
- Pydantic v2 compatibility HOT 10
- Flows pagination not possible HOT 5
- Templates Pagination not functioning HOT 6
- Klaviyo profile unable to subscribe: due to HTTPSConnectionPool HOT 2
- "Invalid cursor provided" Error for "get_events()" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from klaviyo-api-python.