Say you have an existing database-backed Django site. Something simple, like single model containing a record for every minor league baseball team. The model is accessed by one view that lists all the teams, and another that accepts a slug and then creates a detail page all about that team.
Is there a good option for converting the app into a stack of baked out flat files, so that it could be served from a static file service like Amazon's S3?
I've toyed with Hyde but it's not clear to me how it applies to an existing site backed by a database.
Any advice would be very much appreciated. Thank you in advance.
django.contrib.staticfiles provides a convenience management command for gathering static files in a single directory so you can serve them easily. This will copy all files from your static folders into the STATIC_ROOT directory. Use a web server of your choice to serve the files.
Aside from the HTML generated by the server, web applications generally need to serve additional files — such as images, JavaScript, or CSS — necessary to render the complete web page. In Django, we refer to these files as “static files”.
Files are searched by using the enabled finders . The default is to look in all locations defined in STATICFILES_DIRS and in the 'static' directory of apps specified by the INSTALLED_APPS setting.
{% load static %} tells django to load a set of template tags/filters defined in the file static.py (in a folder templatetags in any of the apps of your project). The same way you can define your own tags, put them in a file util_tags.py and load them with {% load util_tags %} .
django-medusa is largely unmaintained. These are some alternatives mentioned in the project's README:
- django-bakery, built and maintained the lovely people at the Los Angeles Times Data Desk. (Read about it here.)
- The alsoicode/django-medusa fork, by Brandon Taylor. Among other things, it's been kept up to date for newer versions of Django.
- django-freeze by Fabio Caccamo.
- django-staticgen by Mishbah Razzaque.
I understand your intent, but any decent framework these days offers some sort of caching mecanism that alleviate the pains of dynamic content. With a properly implemented cache, the difference between static and dynamic will be trivial. Trust me.
Happy coding, friend.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With