简体   繁体   English

django-mptt子项选择在localhost上有效,但在服务器上不起作用

[英]django-mptt children selection works on localhost but not on server

I have the same code on localhost and on server (thanks to mercurial), but it works a little bit different. 我在localhost和服务器上都使用了相同的代码(这要归功于mercurial),但是它的工作方式略有不同。 I want to render category and its subcategories in template using this code: 我想使用以下代码在模板中呈现类别及其子类别:

views.py: 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. 但是,此代码在localhost上完美地工作(子类别正确显示)-在服务器上不起作用,并且{{subcats | length}}返回0。我比较了基于localhost和服务器上MySQL的值-正确和继承应该起作用。 The funniest thing is that the same query works perfectly in manage.py shell on server. 最有趣的是,同一查询在服务器上的manage.py shell中可以完美地工作。

What the hack is wrong with it? hack有什么问题吗?

The problem was solved - it was in .pyc files, which are recreating only after apache is restarted. 问题已解决-它在.pyc文件中,仅在重新启动apache之后才重新创建。 That's why the right code in .py files didn't work. 这就是为什么.py文件中正确的代码无法正常工作的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM