views:

297

answers:

1

We've got a couple of Django flatpages in our project, that are based on actual HTML files. These files undergo some changes once in a while and hence have to updated in the database. So i came up with the idea of simply copying the plain HTML text into a json fixture and do an manage.py loaddata . However the problem is, that there are quite some characters inside the html that have to be escaped in order to pass as json. Does anybody know some script, sed command or maybe even an official django solution for that problem?

+1  A: 

You could write your own manage.py command to read in the HTML file and adding them to the flatpages:

#  assuming variable html contains the new HTML file,
#+ and var id the ID of the flatpage
from django.contrib.flatpages.models import FlatPage
fp = FlatPage.objects.get (id=id)
fp.content = html
fp.save()

Cheers,

Boldewyn