Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any good options for baking out a Django site as static files?

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.

like image 360
palewire Avatar asked Sep 01 '11 23:09

palewire


People also ask

Can Django serve static files?

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.

What are Django static 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”.

Where is Django looking for 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.

What is load static in Django?

{% 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 %} .


2 Answers

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.
like image 190
kqw Avatar answered Oct 04 '22 03:10

kqw


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.

like image 27
stefgosselin Avatar answered Oct 04 '22 01:10

stefgosselin