import os from django.template.loader import render_to_string from django.template import Context from django.urls import reverse from django.conf import settings from builder.base import BuildNew class BuildPages(BuildNew): def build(self): self.build_detail_view() print("building pages") def build_detail_view(self): ''' Grab all the blog posts, render them to a template string and write that out to the filesystem ''' for entry in self.get_model_queryset(): url = entry.get_absolute_url() path, slug = os.path.split(entry.get_absolute_url()) path = '%s/' % path # write html response = self.client.get(url) if slug == 'homepage': slug = 'index' self.write_file(path, response.content, filename=slug) # write txt response = self.client.get('%s.txt' % url) self.write_file(path, response.content, ext='txt', filename=slug) def get_model_queryset(self): return self.model.objects.filter(build=True) def builder(): j = BuildPages("pages", "Page") j.build()