Created
October 21, 2011 12:29
-
-
Save schmidsi/1303701 to your computer and use it in GitHub Desktop.
Custom 404, 500 Templates via FeinCMS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# imports | |
from django.conf import settings | |
from django.db.models import signals | |
from django.dispatch import receiver | |
from django.test.client import Client | |
# your other imports, config here | |
@receiver(signals.post_save, sender=Page) | |
def error_templates(sender, instance, created, raw, using, **kwargs): | |
""" needs the page to be saved 2 times, because the content types are saved after "post_save" """ | |
if instance.slug in ('404', '500'): | |
c = Client() | |
response = c.get(instance.get_absolute_url()) | |
response.render() | |
template_path = os.path.join(settings.MEDIA_ROOT, 'cache') | |
full_template_name = os.path.join(template_path, instance.slug + '.html') | |
template = codecs.open(full_template_name, 'w', 'utf-8') | |
template.write(response.rendered_content) | |
template.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or try this instead: http://komunitasweb.com/2011/06/handling-404-page-on-feincms/