[Fixed]-Best practice when using folium on django

10👍

Amit. As for folium and building maps for user, yes it could make hard work for server, when a lot of users want to compute.
There are solutions for it:

  1. Caching with Redis or Memcached (Django has batteries for it). At this point you can set cache lifetime ~ few seconds to several hours, if coordinates are the same. Django provides view caching, template caching or others.
  2. Save result of maping to db, so if user computes same coodrinates as yesterday – Django will take result from db and show faster to template.
  3. If nothing passes your requirements – just make django faster, turn off unused middlewares, use gunicorn\uwsgi to run and deploy. Locate to web server more RAM and CPU cores (on deploy).
  4. You can try profiling your project , so you can find where is the most computing part at your project. When you found – make it faster.

1👍

Caching is the best way to go, but since you are not an experienced developer I will give you an alternative solution.

It seems that you are recalculating the map each time a user visits that section of your website. One solution is to link directly to the html file, and having the file updated through a CRON task or a Python timer every 30 minutes (or whatever you need). This way you will only calculate once every half an hour for all your users.

Leave a comment