My problem occurs when I try to pass 3 variables to my template tag which I guess takes one or 2 inputs. So any ideas on how to pass 3 template variables to my template tag and here is my code:
views.py:
from shoghlanah.models import *
register = template.Library()
@register.simple_tag
def get_messages(sender_id,receiver_id,task_id):
sender = UserProfile.objects.get(id = sender_id)
receiver =UserProfile.objects.get(id = receiver_id)
task = Task.objects.get(id=task_id)
return messages
message.html :
the url.id and the task_id are template variables
{{ get_messages request.user.id usr.id task_id }}
it gives me an error : Could not parse the remainder: ' request.user.id usr.id task_id' from 'get_messages request.user.id usr.id task_id'
For a django tag, you need to use {% %}
, not the double curly brackets. The double braces signify outputting a value.
See the docs for more.
(Just as a note, I presume that is an extract, but you will also need to {% load %}
your tag too.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.