1đź‘Ť
âś…
It’s definitely possible, depending on how strictly you’re thinking of the “latest post”.
You could put the API reader in it’s own file (reddit.py
) and call the reader when a user GETs your page, then populate the template with the results from the reader.
Or even better, if it doesn’t need to be the absolute latest post, you could store the latest post at a specific point in time (e.g., every 15 minutes) in a database, and then get the relevant object from your model when the user GETs your page. This will likely be much faster than making a live API call and parsing the result while your page loads. You can have the reader asynchronously call the Reddit API every 15 minutes so it doesn’t impact the user’s experience.
👤Josh Maccabee
Source:stackexchange.com