jazzband / wagtailmenus

An app to help you manage and render menus in your Wagtail projects more effectively
MIT License
398 stars 138 forks source link

get_url() got an unexpected keyword argument 'request' #375

Closed inostia closed 4 years ago

inostia commented 4 years ago

Hi, I'm trying to implement sub-menus on a site and I'm hitting an error.

Running:

Django==2.2.9
wagtail==2.7.2
wagtailmenus<3.1

Here's my template code which is throwing an error after adding the sub_menu code:

{% for item in menu_items %}
    <li class="{{item.active_class}}">
        <a href="{{item.href}}">{{item.text}}</a>
        {% if item.sub_menu %}
            <ul class="portal-sub-nav">
                {% for sub_item in item.sub_menu.items %}
                    <li class="{{ sub_item.active_class }}"><a href="{{ sub_item.href }}">{{ sub_item.text }}</a></li>
                {% endfor %}
            </ul>
        {% endif %}
    </li>
{% endfor %}

When I go to render my page, I get a TypeError: get_url() got an unexpected keyword argument 'request'.

The error comes from this line 519 at /wagtailmenus/models/menus.py in _prime_menu_item:

item.href = item.relative_url(current_site, request=request)

The wagtail core code for get_url at line 854 of /wagtail/core/models.py is:

def relative_url(self, current_site, request=None):
    ...
    return self.get_url(request=request, current_site=current_site)

Did I miss something or is this a bug?

inostia commented 4 years ago

I'm not sure what the issue was, but it was solved by using {% sub_menu item %}.