The first step in setting up my new online presence with Django is of course to just present a static home page. The goal is to be up and running as soon as possible, after all. Unfortunately, it’s a bit harder than just slapping your html and css files onto the web server when you’re using a framework like Django.
In Django’s case, I need to install flatpages. That solves the problem of storing static pages, and lets me create them right via the admin interface. But here’s the rub: I want some of those pages preloaded when I deploy – especially during the initial experimental phase, I anticipate wiping out and reinstalling my application quite a few times.
Thankfully, there’s a solution to that too – django-admin dumpdata/loaddata. dumpdata lets you export data from the database into JSON files. I.e. to dump all your flatpages:
django-admin.py dumpdata flatpages > flatpages.json
And obviously, you reload via
django-admin.py dumpdata flatpages > flatpages.json
This is almost all I need – I could certainly encode the re-loading of the data as another deployment step. But – here’s where being in a framework starts paying off – there’s a way to do this more easily. Just rename your dumped data to initial_data.json, and Django will load it into the database whenever you execute a syncdb