I think it should be {% show_authors_for_book book %}, because it's an
custom tag, not a variable.

On Jan 14, 4:18 am, shomain <[EMAIL PROTECTED]> wrote:
> my code list is :
> =================================================
>               1.    mysite/books/models.py
> =================================================
> class Author(models.Model):
>     salutation=models.CharField(maxlength=10)
>     first_name=models.CharField(maxlength=30)
>     last_name=models.CharField(maxlength=40)
>     emal=models.EmailField()
>     headshot=models.ImageField(upload_to='/tmp')
>
>     def __str__(self):
>         return '%s %s' %(self.first_name,self.last_name)
>
>     class Admin:
>         ordering=('email',)
>
> class Book(models.Model):
>     title=models.CharField(maxlength=100)
>     authors=models.ManyToManyField(Author)
>     publisher=models.ForeignKey(Publisher)
>     publication_date=models.DateField()
>
>     def __str__(self):
>         return self.title
> **********************************END**************************************
>
> =================================================
>               2.    mysite/books/views.py
> =================================================
>               ....
> def book_list(request):
>     books=Book.objects.select_related()
>     return render_to_response('books/book_list.html',{'books':books})
> **********************************END**************************************
>
> =================================================
>                3.   mysite/templates/books/book_list.html
> =================================================
> {% load mytags %}
> Book list:
> <ul>
>         {% for book in books %}
>                 <li>
>                         {{ book.title }}<br>
>                         {{ show_authors_for_book book }}
>                 </li>
>         {% endfor %}
> </ul>
> **********************************END**************************************
>
> =================================================
>                4.   mysite/templates/books/book_list.html
> =================================================
> {% load mytags %}
> Book list:
> <ul>
>         {% for book in books %}
>                 <li>
>                         {{ book.title }}<br>
>                         {{ show_authors_for_book book }}
>                 </li>
>         {% endfor %}
> </ul>
> **********************************END**************************************
>
> and then i create a tag file and template file to show authors related
> to book:
> =================================================
>                5.   mysite/books/tempaltetags/mytags.py
> =================================================
> from django import template
> from myDjangoSite1.books.models import Book,Author
>
> register=template.Library()
>
> @register.inclusion_tag('books/show_authors_for_book.html')
> def show_authors_for_book(book):
>         authors=book.authors.all()
>         return {'authors':authors}
> *******************************************************************************
> AND:
> =================================================
>                6.   mysite/templates/books/show_authors_for_book.html
> =================================================
> <ul>
>         {% for author in authors %}
>                 <li>{{author.first_name}} </li>
>         {% endfor %}
> </ul>
> **********************************END**************************************
>
> In url.py, i add a line:
>     (r'^book/$',views.book_list),
>
> All of above code i wrote  is to test how to use inclusion tag,
> but when i test this url,the browse shows error:
> ****************************************************************************************************
> TemplateSyntaxError at /book/
> Could not parse the remainder: book
> Request Method:         GET
> Request URL:    http://127.0.01/book/
> Exception Type:         TemplateSyntaxError
> Exception Value:        Could not parse the remainder: book
> Exception Location:     D:\Python25\lib\site-packages\django\template
> \__init__.py in __init__, line 558
> Template error
>
> In template D:/temp/myDjangoSite1/../myDjangoSite1/templates\books/
> book_list.html, error at line 4
> Could not parse the remainder: book
> 1       {% load mytags %}
> 2       Book list:
> 3       <ul>
> 4       {% for book in books %}
> 5       <li>
> 6       {{ book.title }}<br>
> 7       {{ show_authors_for_book book }}
> 8       </li>
> 9       {% endfor %}
> 10      </ul>
>
> Does somebody knows why???
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to