0

I have the same code on localhost and on server (thanks to mercurial), but it works a little bit different. I want to render category and its subcategories in template using this code:

views.py:

def category(request, category_slug):
    try:
        category = Category.objects.get(slug=category_slug)
    except:
        raise Http404
    subcats = category.get_children()

    return render_to_response('catalogue.html',
            {'category': category,
            'subcats': subcats,
    'header_template':'common/includes/header_%s.html' % flixwood_settings.CURRENT_SITE
            },
            context_instance=RequestContext(request))

template:

<div class='subcats'>
    {% for subcat in subcats %}
    {% ifequal subcat.level 1 %}
    <div class="item">
    <a href="{% url flixwood.views.category category_slug=subcat.slug %}"><img src="{% thumbnail subcat.image 66x66 %}" class="thumb"></a>
    <a href="{% url flixwood.views.category category_slug=subcat.slug %}" class="name">{{ subcat.category }}</a>
                    {{ subcat.short_description|safe }}
    <div class="clear_left"></div>
    </div>
    {% cycle '' '' '<div class="clear_left"></div>'|safe %}
    {% endifequal %}
    {% endfor %}
</div>

but however this code works perfectly on localhost (subcategories are rendering right) - it doesn't work on server, and the {{ subcats|length }} returns 0. I compared values from MySQL bases on localhost and on server - they are right and inheritance should work. The funniest thing is that the same query works perfectly in manage.py shell on server.

What the hack is wrong with it?

Enchantner
  • 1,534
  • 3
  • 20
  • 40
  • Your included code doesn't have {{subcats|length}}. Do you mean level? – Leopd Jul 26 '10 at 19:27
  • any differences in settings.py? what about the admin? any caching working here? and maybe different django versions? – mawimawi Jul 26 '10 at 19:35
  • {{ subcats|length }} returns 0 if I insert it at any place inside template. And there are no differences in files, it is the same repository commit. Django version also matches, it's 1.1 . – Enchantner Jul 26 '10 at 19:53
  • Obvious question, but are you sure the database contents are the same? manage.py dumpdata / loaddata. Different versions of django-mptt installed? – Leopd Jul 26 '10 at 21:02

1 Answers1

0

The problem was solved - it was in .pyc files, which are recreating only after apache is restarted. That's why the right code in .py files didn't work.

Enchantner
  • 1,534
  • 3
  • 20
  • 40