Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

python - 未传递Django自定义模板标记参数(Django Custom Template Tag Arguments not Passed Through)

I have a custom template tag which accesses a model's method to get items.

(我有一个自定义模板标签,可以访问模型的方法来获取项目。)

However, when I pass through the correct amount of arguments, it says I am missing one- get_reminder_items() missing 1 required positional argument: 'remind_list'

(但是,当我传递正确数量的参数时,它表示我缺少一个-get_reminder_items()缺少1个必需的位置参数:'remind_list')

HTML:

(HTML:)

{% for list in remind_lists %} 
    <h3>{{ list.title }}</h3>
    {% get_list_items user.username list as list_items %} 
    {% for item in list_items %}
        <p>{{ item.title }}</p>
    {% endfor %}
{% endfor %}

Custom tag:

(自定义标签:)

register = template.Library()

@register.simple_tag
def get_list_items(authenticated_user, remind_list):
    return RemindList.get_reminder_items(authenticated_user, remind_list) 

Models.py:

(Models.py:)

class RemindList(models.Model):
    parent_user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
    title = models.CharField(max_length=50)

    def get_reminder_items(self, authenticated_user, remind_list):
        user = get_object_or_404(User, username=authenticated_user)
        return Reminder.objects.filter(parent_user=user, remind_type='Regular', parent_list=remind_list)

I have no idea why its doing that, as I have the correct amount of arguments passed through.

(我不知道为什么要这样做,因为我传递了正确数量的参数。)

  ask by Silent Beast translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...