0

I've set up custom 403, 404, and 500 pages as flatpages. Obviously, I don't want these to show up in my navigation menu. Unfortunately, nothing I seem to do can get rid of them.

I want something like:

{% for page in flatpages %}
    {% if page.url != "/403/" and page.url != "/404/" and page.url != "/500/" %}
        <li><a href="{{ page.url }}">{{ page.title }}</a></li>
    {% endif %}
{% endfor %}

...but that doesn't seem to work. In fact, nothing seems to work. I've tried

{% if "error" not in page.url %}

(which would theoretically empty out my menu bar, since I haven't set ANY of the flatpage URLs to include 'error'), but that doesn't work either. Every time I reload the page (even after running manage.py collectstatic and sudo pkill python), all the flatpages are still there. Am I missing something? I don't want to do something like

{% if '/page/' in page.url %}

for each and every one of my flatpages, since that doesn't seem in keeping with DRY (and would be a pain, besides.)

Any suggestions?

swizzard
  • 1,037
  • 1
  • 12
  • 28

1 Answers1

0

Why did you decide to use flatpage for these pages?

You can specify a method in ModelManager class for the model FlatPage, something like this:

def without_error_pages(self):
    return self.exclude(url__in=('/403/', '/404/', '405',))

Then you can use it in your template:

{% for page in flatpages.without_error_pages %}
    <li><a href="{{ page.url }}">{{ page.title }}</a></li>
{% endfor %}

Or you can put self.exclude(url__in=('/403/', '/404/', '405',)) in your view.

Andrei Kaigorodov
  • 2,145
  • 17
  • 17