Re: Custom Template Tag

2016-09-15 Thread 'Abraham Varricatt' via Django users
The idea of doing a POST request during template rendering seems weird. As 
others have mentioned - that's not the place for it. 

But perhaps you issue could be a matter of performing your POST operation 
on the client side, instead of the django server? In that case, it might be 
worth investigating if you could code in some JS inside your template so 
that when the client's browser loads it, the POST operation is called and 
changes are made appropriately on the site. 

Yours,
Abraham V.


On Saturday, 10 September 2016 23:15:28 UTC+5:30, Al Johri wrote:
>
> I'm experimenting with creating templates out of subtemplates. These 
> subtemplates can be either (a) simple text or (b) a hash representing a 
> sentence (i.e. {subject: "Dog", verb: "eat", object: "my {{var}}", tense: 
> "past"}). I would like to run the hashes through a realization engine which 
> would render as "Dog ate my homework" given a context dictionary of {var: 
> "homework"}. The realization engine is accessed via a REST API.
>
> Does that make sense?
>
> On Friday, September 2, 2016 at 1:38:39 AM UTC-4, Constantine Covtushenko 
> wrote:
>>
>> Hi All,
>> There is no valuable reason to do it in the template. And no matter how 
>> to ate using it, cause template should only present view model(s).
>>
>> But if you tell us your intention may be we can suggest a better place 
>> for such request?
>>
>> Regards,
>>
>> On Sep 2, 2016 6:03 AM, "Al Johri"  wrote:
>>
>>> Ludovic,
>>>
>>> I'm using the templates for a different purpose, not in a web framework 
>>> or view.
>>>
>>> Thanks,
>>>
>>> Al
>>>
>>> On Thursday, September 1, 2016 at 8:09:29 AM UTC-4, ludovic coues wrote:

 I wouldn't do it this way. 
 Personally, I would make the POST request in the view function, put 
 the return value in the context. The template isn't a good place to 
 have logic. It should only take data and format them. 

 2016-09-01 5:33 GMT+02:00 Al Johri : 
 > Hi Django Users, 
 > 
 > I want to make a custom template tag where the tag's renderer needs 
 to make 
 > a POST request. 
 > 
 > 
 https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#writing-the-renderer
  
 > 
 https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#thread-safety-considerations
  
 > 
 > Is it possible to render the nodes of a template in multiple threads? 
 I 
 > would ideally like those POST requests to happen at the same time. 
 > 
 > Does anyone know of some similar project? 
 > 
 > Thanks, 
 > 
 > Al 
 > 
 > -- 
 > You received this message because you are subscribed to the Google 
 Groups 
 > "Django users" group. 
 > To unsubscribe from this group and stop receiving emails from it, 
 send an 
 > email to django-users...@googlegroups.com. 
 > To post to this group, send email to django...@googlegroups.com. 
 > Visit this group at https://groups.google.com/group/django-users. 
 > To view this discussion on the web visit 
 > 
 https://groups.google.com/d/msgid/django-users/84ccc6dc-ae1d-404c-9a05-1b72fc36a778%40googlegroups.com.
  

 > For more options, visit https://groups.google.com/d/optout. 



 -- 

 Cordialement, Coues Ludovic 
 +336 148 743 42 

>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/7eaa219b-ddee-4fa2-8ffb-37d04f168965%40googlegroups.com
>>>  
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/80de9c3d-5ca6-40ba-b521-9cb719a25f9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom Template Tag

2016-09-10 Thread Al Johri
I'm experimenting with creating templates out of subtemplates. These 
subtemplates can be either (a) simple text or (b) a hash representing a 
sentence (i.e. {subject: "Dog", verb: "eat", object: "my {{var}}", tense: 
"past"}). I would like to run the hashes through a realization engine which 
would render as "Dog ate my homework" given a context dictionary of {var: 
"homework"}. The realization engine is accessed via a REST API.

Does that make sense?

On Friday, September 2, 2016 at 1:38:39 AM UTC-4, Constantine Covtushenko 
wrote:
>
> Hi All,
> There is no valuable reason to do it in the template. And no matter how to 
> ate using it, cause template should only present view model(s).
>
> But if you tell us your intention may be we can suggest a better place for 
> such request?
>
> Regards,
>
> On Sep 2, 2016 6:03 AM, "Al Johri" > 
> wrote:
>
>> Ludovic,
>>
>> I'm using the templates for a different purpose, not in a web framework 
>> or view.
>>
>> Thanks,
>>
>> Al
>>
>> On Thursday, September 1, 2016 at 8:09:29 AM UTC-4, ludovic coues wrote:
>>>
>>> I wouldn't do it this way. 
>>> Personally, I would make the POST request in the view function, put 
>>> the return value in the context. The template isn't a good place to 
>>> have logic. It should only take data and format them. 
>>>
>>> 2016-09-01 5:33 GMT+02:00 Al Johri : 
>>> > Hi Django Users, 
>>> > 
>>> > I want to make a custom template tag where the tag's renderer needs to 
>>> make 
>>> > a POST request. 
>>> > 
>>> > 
>>> https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#writing-the-renderer
>>>  
>>> > 
>>> https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#thread-safety-considerations
>>>  
>>> > 
>>> > Is it possible to render the nodes of a template in multiple threads? 
>>> I 
>>> > would ideally like those POST requests to happen at the same time. 
>>> > 
>>> > Does anyone know of some similar project? 
>>> > 
>>> > Thanks, 
>>> > 
>>> > Al 
>>> > 
>>> > -- 
>>> > You received this message because you are subscribed to the Google 
>>> Groups 
>>> > "Django users" group. 
>>> > To unsubscribe from this group and stop receiving emails from it, send 
>>> an 
>>> > email to django-users...@googlegroups.com. 
>>> > To post to this group, send email to django...@googlegroups.com. 
>>> > Visit this group at https://groups.google.com/group/django-users. 
>>> > To view this discussion on the web visit 
>>> > 
>>> https://groups.google.com/d/msgid/django-users/84ccc6dc-ae1d-404c-9a05-1b72fc36a778%40googlegroups.com.
>>>  
>>>
>>> > For more options, visit https://groups.google.com/d/optout. 
>>>
>>>
>>>
>>> -- 
>>>
>>> Cordialement, Coues Ludovic 
>>> +336 148 743 42 
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/7eaa219b-ddee-4fa2-8ffb-37d04f168965%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2718aa6b-3f5c-4c38-843b-773d41d944e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom Template Tag

2016-09-01 Thread Constantine Covtushenko
Hi All,
There is no valuable reason to do it in the template. And no matter how to
ate using it, cause template should only present view model(s).

But if you tell us your intention may be we can suggest a better place for
such request?

Regards,

On Sep 2, 2016 6:03 AM, "Al Johri"  wrote:

> Ludovic,
>
> I'm using the templates for a different purpose, not in a web framework or
> view.
>
> Thanks,
>
> Al
>
> On Thursday, September 1, 2016 at 8:09:29 AM UTC-4, ludovic coues wrote:
>>
>> I wouldn't do it this way.
>> Personally, I would make the POST request in the view function, put
>> the return value in the context. The template isn't a good place to
>> have logic. It should only take data and format them.
>>
>> 2016-09-01 5:33 GMT+02:00 Al Johri :
>> > Hi Django Users,
>> >
>> > I want to make a custom template tag where the tag's renderer needs to
>> make
>> > a POST request.
>> >
>> > https://docs.djangoproject.com/en/1.10/howto/custom-template
>> -tags/#writing-the-renderer
>> > https://docs.djangoproject.com/en/1.10/howto/custom-template
>> -tags/#thread-safety-considerations
>> >
>> > Is it possible to render the nodes of a template in multiple threads? I
>> > would ideally like those POST requests to happen at the same time.
>> >
>> > Does anyone know of some similar project?
>> >
>> > Thanks,
>> >
>> > Al
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Django users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an
>> > email to django-users...@googlegroups.com.
>> > To post to this group, send email to django...@googlegroups.com.
>> > Visit this group at https://groups.google.com/group/django-users.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msgid/django-users/84ccc6dc-ae1d
>> -404c-9a05-1b72fc36a778%40googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>>
>> Cordialement, Coues Ludovic
>> +336 148 743 42
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/7eaa219b-ddee-4fa2-8ffb-37d04f168965%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK52boXxVGX4JT9o2%3DKrtBsFDVr%2BrY9ZVpfLruWED3NUcW58cw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom Template Tag

2016-09-01 Thread Al Johri
Ludovic,

I'm using the templates for a different purpose, not in a web framework or 
view.

Thanks,

Al

On Thursday, September 1, 2016 at 8:09:29 AM UTC-4, ludovic coues wrote:
>
> I wouldn't do it this way. 
> Personally, I would make the POST request in the view function, put 
> the return value in the context. The template isn't a good place to 
> have logic. It should only take data and format them. 
>
> 2016-09-01 5:33 GMT+02:00 Al Johri >: 
> > Hi Django Users, 
> > 
> > I want to make a custom template tag where the tag's renderer needs to 
> make 
> > a POST request. 
> > 
> > 
> https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#writing-the-renderer
>  
> > 
> https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#thread-safety-considerations
>  
> > 
> > Is it possible to render the nodes of a template in multiple threads? I 
> > would ideally like those POST requests to happen at the same time. 
> > 
> > Does anyone know of some similar project? 
> > 
> > Thanks, 
> > 
> > Al 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to django-users...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/84ccc6dc-ae1d-404c-9a05-1b72fc36a778%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
>
> Cordialement, Coues Ludovic 
> +336 148 743 42 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7eaa219b-ddee-4fa2-8ffb-37d04f168965%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom Template Tag

2016-09-01 Thread ludovic coues
I wouldn't do it this way.
Personally, I would make the POST request in the view function, put
the return value in the context. The template isn't a good place to
have logic. It should only take data and format them.

2016-09-01 5:33 GMT+02:00 Al Johri :
> Hi Django Users,
>
> I want to make a custom template tag where the tag's renderer needs to make
> a POST request.
>
> https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#writing-the-renderer
> https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#thread-safety-considerations
>
> Is it possible to render the nodes of a template in multiple threads? I
> would ideally like those POST requests to happen at the same time.
>
> Does anyone know of some similar project?
>
> Thanks,
>
> Al
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/84ccc6dc-ae1d-404c-9a05-1b72fc36a778%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEuG%2BTb_9_0eEV3MQR7EqxQGAxK%2BcfNNCy%3Df3vf3%2B9DOZiohoA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom template tag problem: "No module named models"

2012-11-08 Thread nolurking
I had the same issue, fixed it with a variation on Jim D.'s solution.

import bookmarks

then bookmarks.models.Bookmark.objects.filter(...)

On Tuesday, October 14, 2008 11:38:20 PM UTC-7, Chris Amico wrote:
>
> I have a simple bookmarks model based on the one in James Bennett's  href="http://code.google.com/p/cab/source/browse/trunk/models.py? 
> r=130 
> ">Cab 
> application. I'm using a generic relation so it can 
> live in its own app and a user can bookmark any object on the site 
> (I'm planning on reusing this app on a couple projects). I'm running 
> into a problem creating an {% if_bookmarked %} template tag. 
>
> When I load the tag library I get this error: 'bookmarks' is not a 
> valid tag library: Could not load template library from 
> django.templatetags.bookmarks, No module named models 
>
> Here's what the tag module looks like: 
>
> from django import template 
> from django.contrib.contenttypes.models import ContentType 
> from bookmarks.models import Bookmark 
>
>
> class IfBookmarkedNode(template.Node): 
> def __init__(self, user, obj, nodelist_true, nodelist_false): 
> self.nodelist_true = nodelist_true 
> self.nodelist_false = nodelist_false 
> self.user_id = template.Variable(user_id) 
> self.obj = template.Variable(obj) 
>
> def render(self, context): 
> try: 
> self.user_id = template.resolve_variable(self.user_id, 
> context) 
> self.obj = template.resolve_variable(self.obj, context) 
> except template.VariableDoesNotExist: 
> return '' 
> ctype = ContentType.objects.get_for_model(obj) 
> if Bookmark.objects.filter(content_type=ctype, 
> object_id=obj.id, user__pk=user_id.id): 
> return self.nodelist_true.render(context) 
> else: 
> return self.nodelist_false.render(context) 
>
>
> def do_if_bookmarked(parser, token): 
> bits = token.contents.split() 
> if len(bits) != 3: 
> raise template.TemplateSyntaxError("'%s' tag takes exactly two 
> arguments" % bits[0]) 
> nodelist_true = parser.parse(('else', 'endif_bookmarked')) 
> token = parser.next_token() 
> if token.contents == 'else': 
> nodelist_false = parser.parse(('endif_bookmarked',)) 
> parser.delete_first_token() 
> else: 
> nodelist_false = template.NodeList() 
> return IfBookmarkedNode(bits[1], bits[2], nodelist_true, 
> nodelist_false) 
>
>
> And this is the model it should be importing: 
>
>
> class Bookmark(models.Model): 
> "A bookmarked item, saved by a user with a timestamp" 
> # generic relation 
> content_type = models.ForeignKey(ContentType) 
> object_id = models.PositiveIntegerField() 
> content_object = generic.GenericForeignKey('content_type', 
> 'object_id') 
>
> # who and when 
> user = models.ForeignKey(User) 
> timestamp = models.DateTimeField(auto_now_add=True) 
>
>
>
> The bookmarking model works fine on its own, and I've gotten the 
> functions in the template tag to work in isolation in the interpreter, 
> but when I load the tag library it breaks the template. What am I 
> missing here?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Gqnjk38KVP0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: custom template tag. success message after form-submit in the same .html file

2011-08-15 Thread Konstantin Sushenko
hello,

you can just add a context variable 'submitted' to your context in
your view's get_context_data

konstantin

On Aug 15, 4:06 am, doniyor  wrote:
> Hi There,
>
> I am heading well now, but have still some confusing things here..
>
> this is my html file, where i want to get a success message after the
> form is submitted:
>
> __
> 
>         {% load forms %}
>         {% if submitted %}
>                 {{ success }}
>         {% else %}
>              
>         {% endif %}
>         Clear cache:  Cache leeren  a>
> 
> -
> this is my def  in templatetags folder:
> 
> success = 'Cache erfolgreich geleert'
>
> def submitted(self):
>     if request.method == 'GET':
>         return True
>
> register.tag('submitted', submitted)
> 
>
> BUT i dont see anything after submission of the form. where is my
> mistake, can you please help ?,
>
> thanks in advance..
>
> Doni

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Custom template tag -- Not registered?

2011-04-29 Thread Kenny Meyer
On Fri, Apr 29, 2011 at 5:11 PM, Daniel Roseman  wrote:
> On Friday, 29 April 2011 21:24:44 UTC+1, Kenny Meyer wrote:
>>
>> Hello,
>>
>> I have the following inclusion tag in templatetags/show_submissions.py :
>>
>> ## BOF
>>
>> register = template.Library()
>>
>> @register.inclusion_tag('competition/templatetags/show_submissions.html')
>> def show_submissions(participant):
>>     submissions = Submission.objects.get(participant=participant)
>>     return {"submissions": submissions}
>>
>> ## EOF
>>
>> Whenever Django reaches the following line in my templates:
>>
>>     {% show_submissions user.participant %}
>>
>> A TemplateSyntaxError gets raised, which I interpret as "I don't find
>> your templatetag". Here's the full traceback:
>> http://dpaste.com/537298/
>>
>> Observations:
>> * Restarted the dev server several times after registering the tag,
>> and got the same results.
>> * templatetags/ folder has a __init__.py
>> * Using Django 1.3
>>
>> Any ideas why I cannot use this inclusion tag?
>>
>> Kenny
>
> Your template doesn't seem to have {% load show_submissions %} anywhere.

Oh, I really forgot that... there was indeed no {% load
show_submissions %} anywhere.

Thanks for your kind help!

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Custom template tag -- Not registered?

2011-04-29 Thread Daniel Roseman
On Friday, 29 April 2011 21:24:44 UTC+1, Kenny Meyer wrote:
>
> Hello,
>
> I have the following inclusion tag in templatetags/show_submissions.py :
>
> ## BOF
>
> register = template.Library()
>
> @register.inclusion_tag('competition/templatetags/show_submissions.html')
> def show_submissions(participant):
> submissions = Submission.objects.get(participant=participant)
> return {"submissions": submissions}
>
> ## EOF
>
> Whenever Django reaches the following line in my templates:
>
> {% show_submissions user.participant %}
>
> A TemplateSyntaxError gets raised, which I interpret as "I don't find
> your templatetag". Here's the full traceback:
> http://dpaste.com/537298/
>
> Observations:
> * Restarted the dev server several times after registering the tag,
> and got the same results.
> * templatetags/ folder has a __init__.py
> * Using Django 1.3
>
> Any ideas why I cannot use this inclusion tag?
>
> Kenny
>

Your template doesn't seem to have {% load show_submissions %} anywhere.
--
DR. 

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Custom template tag for a chaptered document?

2010-01-03 Thread Tomasz Zieliński
On 30 Gru 2009, 01:26, Stodge  wrote:
> I need to write a custom tag. I have a hierarchy of objects that I
> want to turn into a chaptered document. But I want to be able to build
> and display the document in a template AND generate a PDF or other
> format from a view. Can I write a custom template tag and use it in a
> template and from a view?? Or is there already something like this out
> there

You could write a function that does what you need and can be used in
views,
then write template tag as an thin adaptor around this function - so
that
you can use it in templates.

--
Tomasz Zielinski
http://pyconsultant.eu

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Custom template tag problem: "No module named models"

2009-10-01 Thread Karen Tracey
On Thu, Oct 1, 2009 at 8:47 PM, shacker  wrote:

>
> Found the problem. There were no namespace problems in my template
> tag, but there were (are) in the external app I'm using, which is the
> RSS aggregator used by the djangoproject.com site itself:
>
>
> http://code.djangoproject.com/browser/djangoproject.com/django_website/apps/aggregator
>
> The app is called "aggregator" and it includes  templatetags/
> aggregator.py
>
> So apparently this hasn't bitten the devs of the djangoproject.com
> site, but it bit me!
>
>
That template tags file avoids "from aggregator.models import" and uses
instead:

from django_website.apps.aggregator.models import Feed

That's an alternative to renaming the template tags file, an import that
sufficiently qualifies the duplicated name so as to avoid the problem.

Karen

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2009-10-01 Thread shacker

On Oct 1, 4:00 pm, Karen Tracey  wrote:

>
> Yes, you must simply ensure you name things in such a way that the models
> module you want to access is not hidden by something else. The original
> problem noted in the thread you reference resulted from re-using the
> application's name (bookmarks) as the name of the template tags file
> (bookmarks.py), which then attempted to import from the applications models
> (bookmarks.models).  Renaming the bookmarks.py template tags file to

Found the problem. There were no namespace problems in my template
tag, but there were (are) in the external app I'm using, which is the
RSS aggregator used by the djangoproject.com site itself:

http://code.djangoproject.com/browser/djangoproject.com/django_website/apps/aggregator

The app is called "aggregator" and it includes  templatetags/
aggregator.py

So apparently this hasn't bitten the devs of the djangoproject.com
site, but it bit me!

> Since you didn't include any specifics of the names you were using for
> anything here, it's hard to say what exactly was causing the problem in your
> case.  But there are no restrictions placed by Django on what a template
> tags library is "allowed" to access. Django doesn't attempt to enforce any
> sort of "only touch stuff from your own app" requirement.

That's what I thought :)
Thanks for nudging me to look more closely at this.

Scot

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2009-10-01 Thread Karen Tracey
On Thu, Oct 1, 2009 at 6:16 PM, shacker  wrote:

>
> Google apparently won't let me reply to an older thread:
>
> http://groups.google.com/group/django-users/browse_thread/thread/94239f017df4b12f
> so starting a new one.
>
> I too was hitting the "No module named models" problem when creating a
> template tag. I had the tag working perfectly when it communicated
> exclusively with the models belong to the app the templatetag lived
> in. But I needed to modify the tag to also get data from models in
> another of the project's apps. That other app imports fine from
> wherever I use it, but I could not get its models to be imported into
> the template tag. No amount of path tweaking, debugging, deleting .pyc
> files etc. would help.
>
> The docs say: "Custom template tags and filters must live inside a
> Django app. If they relate to an existing app it makes sense to bundle
> them there; otherwise, you should create a new app to hold them."
>
> They do not say whether a template tag should be able to talk to
> models from two different apps, but I assume they would be able to. My
> final solution was to merge the two apps into one. Not ideal, but not
> horrible in this particular circumstance. I did not try creating a new
> app just to hold the templatetag.
>
> Anyway, the question is, shouldn't template tags that live inside one
> app's directory also be able to get data from other apps?
>
>
Yes, you must simply ensure you name things in such a way that the models
module you want to access is not hidden by something else. The original
problem noted in the thread you reference resulted from re-using the
application's name (bookmarks) as the name of the template tags file
(bookmarks.py), which then attempted to import from the applications models
(bookmarks.models).  Renaming the bookmarks.py template tags file to
bookmark_tags, and deleting all old .pyc files resulting from the previous
name, fixed the problem.  (Why it took "many refreshes" to discover an
errant .pyc file that continued to cause trouble is unclear to me, I'm
unfamiliar with the tool mentioned as being used.)

Since you didn't include any specifics of the names you were using for
anything here, it's hard to say what exactly was causing the problem in your
case.  But there are no restrictions placed by Django on what a template
tags library is "allowed" to access. Django doesn't attempt to enforce any
sort of "only touch stuff from your own app" requirement.

Karen

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Custom Template Tag - Passing variable for use in tag processing

2009-01-29 Thread phoebebright

This is the final code which works in case it helps anyone else.
Thanks again.

In the template:

{% page_links category %}



In templatetags file

@register.tag(name="page_links")
def get_page_links(parser,token):

tag_name, category = token.contents.split()

return PageLink(category)


class PageLink(template.Node):

def __init__(self, category):

self.category = template.Variable(category)

def render(self, context):
cat = self.category.resolve(context)

if cat=='business':
pages=BusinessPage.objects.filter
(is_live=True).select_related().order_by('order')
elif cat=='community':
pages=CommunityPage.objects.filter
(is_live=True).select_related().order_by('order')
elif cat=='tourism':
pages=TourismPage.objects.filter
(is_live=True).select_related().order_by('order')

else:
pages = False


context['pages'] = pages

return ''



On Jan 29, 3:22 pm, phoebebright  wrote:
> You understood perfectly.  It was just another case of my not
> understanding the documentation.  Your explanation makes perfect
> sense.
>
> Many thanks.
>
> On Jan 27, 6:45 pm, Eric Abrahamsen  wrote:
>
> > On Jan 28, 2009, at 1:52 AM, phoebebright wrote:
>
> > > I have duplicated as best I can the processing for handling variables
> > > incustomtemplatetagsmentioned in an earlier post but it's not
> > > working for me as I need the value of the variable before I parse it.
> > > Is there another way of making the variable available?
>
> > > The tag is being called from the tempalte with:
>
> > > {% page_links "category"  %}
>
> > > Where category is being passed into thetemplatefrom a view.  (also
> > > tried "{{category}}" and {{category}} and category)
>
> > > I want to use the value of category to determine which list of pages
> > > to return.
>
> > > I KNOW THIS DOESN"T WORK:
>
> > > @register.tag(name="page_links")
> > > def get_page_links(parser,token):
> > >    tag_name, cat = token.contents.split()
> > >    return PageLink(cat[1:-1])
>
> > > class PageLink(template.Node):
>
> > >    def __init__(self, cat):
>
> > >        cat=template.Variable(cat)
> > >        print cat   <-  outputs category
> > >        if cat=='business':
> > >            pages=BusinessPage.objects.filter
> > > (is_live=True).select_related().order_by('order')
> > >        elif cat=='community':
> > >            pages=CommunityPage.objects.filter
> > > (is_live=True).select_related().order_by('order')
> > >        elif cat=='tourism':
> > >            pages=TourismPage.objects.filter
> > > (is_live=True).select_related().order_by('order')
>
> > >        else:
> > >            pages = False
>
> > >            self.pages = pages
>
> > >    def render(self, context):
> > >        context['pages'] = self.pages
>
> > >        return ''
>
> > I might be missing something you're trying to do here, but the usual  
> > method for resolving a variable in acustomtemplatetag is to first  
> > put it into the tag (without quotes) like so:
> > {% page_links category %}
>
> > Then attach that to your PageLink node in its __init__ method as a  
> > Variable:
> > self.cat =template.Variable(cat)
>
> > Then inside the render method first resolve it:
> > category = self.cat.resolve(context)
>
> > and then check the value of category against your various models. That  
> > all has to be done in render, not __init__, because context is only  
> > available in render.
>
> > This is all straight out of the 
> > docs:http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#pass...
>
> > Apologies in advance if I've misunderstood what you're trying to do...
>
> > Eric
>
> > > This code works fine as long as I call it like this:
>
> > > {% page_links "business" %}
>
> > > @register.tag(name="page_links")
> > > def get_page_links(parser,token):
>
> > >        tag_name, cat = token.contents.split()
> > >        cat = cat[1:-1]
>
> > >        if cat=='business':
> > >            pages=BusinessPage.objects.filter
> > > (is_live=True).select_related().order_by('order')
> > >        elif cat=='community':
> > >            pages=CommunityPage.objects.filter
> > > (is_live=True).select_related().order_by('order')
> > >        elif cat=='tourism':
> > >            pages=TourismPage.objects.filter
> > > (is_live=True).select_related().order_by('order')
> > >        else:
> > >            pages = False
>
> > >        return PageLink(pages)
>
> > > class PageLink(template.Node):
>
> > >    def __init__(self, pages):
> > >        self.pages = pages
>
> > >    def render(self, context):
> > >        context['pages'] = self.pages
>
> > >        return ''
>
>
--~--~-~--~~~---~--~~
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 
django-users+unsubs

Re: Custom Template Tag - Passing variable for use in tag processing

2009-01-29 Thread phoebebright

You understood perfectly.  It was just another case of my not
understanding the documentation.  Your explanation makes perfect
sense.

Many thanks.

On Jan 27, 6:45 pm, Eric Abrahamsen  wrote:
> On Jan 28, 2009, at 1:52 AM, phoebebright wrote:
>
>
>
>
>
> > I have duplicated as best I can the processing for handling variables
> > incustomtemplatetagsmentioned in an earlier post but it's not
> > working for me as I need the value of the variable before I parse it.
> > Is there another way of making the variable available?
>
> > The tag is being called from the tempalte with:
>
> > {% page_links "category"  %}
>
> > Where category is being passed into thetemplatefrom a view.  (also
> > tried "{{category}}" and {{category}} and category)
>
> > I want to use the value of category to determine which list of pages
> > to return.
>
> > I KNOW THIS DOESN"T WORK:
>
> > @register.tag(name="page_links")
> > def get_page_links(parser,token):
> >    tag_name, cat = token.contents.split()
> >    return PageLink(cat[1:-1])
>
> > class PageLink(template.Node):
>
> >    def __init__(self, cat):
>
> >        cat=template.Variable(cat)
> >        print cat   <-  outputs category
> >        if cat=='business':
> >            pages=BusinessPage.objects.filter
> > (is_live=True).select_related().order_by('order')
> >        elif cat=='community':
> >            pages=CommunityPage.objects.filter
> > (is_live=True).select_related().order_by('order')
> >        elif cat=='tourism':
> >            pages=TourismPage.objects.filter
> > (is_live=True).select_related().order_by('order')
>
> >        else:
> >            pages = False
>
> >            self.pages = pages
>
> >    def render(self, context):
> >        context['pages'] = self.pages
>
> >        return ''
>
> I might be missing something you're trying to do here, but the usual  
> method for resolving a variable in acustomtemplatetag is to first  
> put it into the tag (without quotes) like so:
> {% page_links category %}
>
> Then attach that to your PageLink node in its __init__ method as a  
> Variable:
> self.cat =template.Variable(cat)
>
> Then inside the render method first resolve it:
> category = self.cat.resolve(context)
>
> and then check the value of category against your various models. That  
> all has to be done in render, not __init__, because context is only  
> available in render.
>
> This is all straight out of the 
> docs:http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#pass...
>
> Apologies in advance if I've misunderstood what you're trying to do...
>
> Eric
>
>
>
> > This code works fine as long as I call it like this:
>
> > {% page_links "business" %}
>
> > @register.tag(name="page_links")
> > def get_page_links(parser,token):
>
> >        tag_name, cat = token.contents.split()
> >        cat = cat[1:-1]
>
> >        if cat=='business':
> >            pages=BusinessPage.objects.filter
> > (is_live=True).select_related().order_by('order')
> >        elif cat=='community':
> >            pages=CommunityPage.objects.filter
> > (is_live=True).select_related().order_by('order')
> >        elif cat=='tourism':
> >            pages=TourismPage.objects.filter
> > (is_live=True).select_related().order_by('order')
> >        else:
> >            pages = False
>
> >        return PageLink(pages)
>
> > class PageLink(template.Node):
>
> >    def __init__(self, pages):
> >        self.pages = pages
>
> >    def render(self, context):
> >        context['pages'] = self.pages
>
> >        return ''
>
>
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Custom Template Tag - Passing variable for use in tag processing

2009-01-27 Thread Eric Abrahamsen


On Jan 28, 2009, at 1:52 AM, phoebebright wrote:

>
> I have duplicated as best I can the processing for handling variables
> in custom template tags mentioned in an earlier post but it's not
> working for me as I need the value of the variable before I parse it.
> Is there another way of making the variable available?
>
> The tag is being called from the tempalte with:
>
> {% page_links "category"  %}
>
> Where category is being passed into the template from a view.  (also
> tried "{{category}}" and {{category}} and category)
>
> I want to use the value of category to determine which list of pages
> to return.
>
> I KNOW THIS DOESN"T WORK:
>
> @register.tag(name="page_links")
> def get_page_links(parser,token):
>tag_name, cat = token.contents.split()
>return PageLink(cat[1:-1])
>
> class PageLink(template.Node):
>
>def __init__(self, cat):
>
>cat= template.Variable(cat)
>print cat   <-  outputs category
>if cat=='business':
>pages=BusinessPage.objects.filter
> (is_live=True).select_related().order_by('order')
>elif cat=='community':
>pages=CommunityPage.objects.filter
> (is_live=True).select_related().order_by('order')
>elif cat=='tourism':
>pages=TourismPage.objects.filter
> (is_live=True).select_related().order_by('order')
>
>else:
>pages = False
>
>self.pages = pages
>
>def render(self, context):
>context['pages'] = self.pages
>
>return ''
>

I might be missing something you're trying to do here, but the usual  
method for resolving a variable in a custom template tag is to first  
put it into the tag (without quotes) like so:
{% page_links category %}

Then attach that to your PageLink node in its __init__ method as a  
Variable:
self.cat = template.Variable(cat)

Then inside the render method first resolve it:
category = self.cat.resolve(context)

and then check the value of category against your various models. That  
all has to be done in render, not __init__, because context is only  
available in render.

This is all straight out of the docs:
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#passing-template-variables-to-the-tag

Apologies in advance if I've misunderstood what you're trying to do...

Eric




>
> This code works fine as long as I call it like this:
>
> {% page_links "business" %}
>
> @register.tag(name="page_links")
> def get_page_links(parser,token):
>
>tag_name, cat = token.contents.split()
>cat = cat[1:-1]
>
>if cat=='business':
>pages=BusinessPage.objects.filter
> (is_live=True).select_related().order_by('order')
>elif cat=='community':
>pages=CommunityPage.objects.filter
> (is_live=True).select_related().order_by('order')
>elif cat=='tourism':
>pages=TourismPage.objects.filter
> (is_live=True).select_related().order_by('order')
>else:
>pages = False
>
>return PageLink(pages)
>
> class PageLink(template.Node):
>
>def __init__(self, pages):
>self.pages = pages
>
>def render(self, context):
>context['pages'] = self.pages
>
>return ''
> >


--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2008-11-18 Thread bruno desthuilliers



On 15 oct, 09:19, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> On Wed, 2008-10-15 at 01:08 -0700, bruno desthuilliers wrote:
>
> [...]
>
> > FWIW, I just don't understand why each an every example in the
> > Django's manual insists on using this projectname.appname scheme.
>
> "Insists" is a rather strong word, since nowhere does it say "do this or
> else".

(just reading this post now - a bit late, but...)

Malcom, I'm not a native English speaker, so I sometimes  fail to
convey the exact nuance. Please bear with me !-)


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2008-11-18 Thread Jim D.

I came across this thread and was having the exact same problem.
*Exactly* the same... I had tried everything you tried to no avail.

I actually fixed it by taking a hint from something that came out of
following along with your debug session in my own code.

I'll put my solution in terms of your code.

This fails:

from django import template
from django.contrib.contenttypes.models import ContentType
from bookmarks.models import Bookmark

This works:

from django import template
from django.contrib.contenttypes.models import ContentType
import bookmarks
from bookmarks.models import Bookmark

I'm not quite sure why though. I wonder, did your solution end up
looking anything like the above?

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom Template Tag with {% end... %} tag

2008-10-20 Thread Erik Allik

I guess it was easier for me to type it myself than search through the  
new documentation. :)

Erik

On 20.10.2008, at 5:49, James Bennett wrote:

>
> On Sun, Oct 19, 2008 at 4:20 PM, Erik Allik <[EMAIL PROTECTED]> wrote:
>> In the compilation function of your template tag, you can force the
>> parser to parse until tag named "endyourcustomtag" by calling  
>> nodelist
>> = parser.parse(("endyourcustomtag", ). This will return the contents
>> of your block tag as a list of nodes. Finally you can "drop off" the
>> end tag by calling parser.delete_first_token() because parser.parse
>> left the parser in a state where "endyourcustomtag" is still  
>> unparsed.
>
> And there's even documentation on how to do this, based on the example
> of the built-in comment/endcomment:
>
> http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#parsing-until-another-block-tag
>
>
> -- 
> "Bureaucrat Conrad, you are technically correct -- the best kind of  
> correct."
>
> >


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom Template Tag with {% end... %} tag

2008-10-19 Thread James Bennett

On Sun, Oct 19, 2008 at 4:20 PM, Erik Allik <[EMAIL PROTECTED]> wrote:
> In the compilation function of your template tag, you can force the
> parser to parse until tag named "endyourcustomtag" by calling nodelist
> = parser.parse(("endyourcustomtag", ). This will return the contents
> of your block tag as a list of nodes. Finally you can "drop off" the
> end tag by calling parser.delete_first_token() because parser.parse
> left the parser in a state where "endyourcustomtag" is still unparsed.

And there's even documentation on how to do this, based on the example
of the built-in comment/endcomment:

http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#parsing-until-another-block-tag


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom Template Tag with {% end... %} tag

2008-10-19 Thread Siah

Thank you!
Sia

On Oct 19, 5:20 pm, Erik Allik <[EMAIL PROTECTED]> wrote:
> In the compilation function of your template tag, you can force the  
> parser to parse until tag named "endyourcustomtag" by calling nodelist  
> = parser.parse(("endyourcustomtag", ). This will return the contents  
> of your block tag as a list of nodes. Finally you can "drop off" the  
> end tag by calling parser.delete_first_token() because parser.parse  
> left the parser in a state where "endyourcustomtag" is still unparsed.
>
> Find a find on "def do_if(parser, token):" -- check out how the if tag  
> has been written.
>
> Erik
>
> On 19.10.2008, at 23:24, Siah wrote:
>
>
>
> > Hi,
>
> > I can't understand how template tags such as if, for and ifequal
> > manage to have an accompanying endif, endfor and endifequal, and I
> > can't have it. Or I can't manage to find out how to do it. So, I
> > basically want to do something like:
>
> > {% customTag %} hello {% endcustomTag %}
>
> > and within my customTag implementation, have 'hello' as a parameter.
>
> > Thanks for all the help in advance,
> > Sia
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom Template Tag with {% end... %} tag

2008-10-19 Thread Erik Allik

In the compilation function of your template tag, you can force the  
parser to parse until tag named "endyourcustomtag" by calling nodelist  
= parser.parse(("endyourcustomtag", ). This will return the contents  
of your block tag as a list of nodes. Finally you can "drop off" the  
end tag by calling parser.delete_first_token() because parser.parse  
left the parser in a state where "endyourcustomtag" is still unparsed.

Find a find on "def do_if(parser, token):" -- check out how the if tag  
has been written.

Erik

On 19.10.2008, at 23:24, Siah wrote:

>
> Hi,
>
> I can't understand how template tags such as if, for and ifequal
> manage to have an accompanying endif, endfor and endifequal, and I
> can't have it. Or I can't manage to find out how to do it. So, I
> basically want to do something like:
>
> {% customTag %} hello {% endcustomTag %}
>
> and within my customTag implementation, have 'hello' as a parameter.
>
> Thanks for all the help in advance,
> Sia
> >


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2008-10-17 Thread Chris Amico

I think it's fixed now. After much refreshing (I'm editing in Coda) a
bookmarks.pyc file appeared. Once that was gone, the tag library did
load correctly. I have a different error coming up now, which I'll try
to fix or post separately if I can't.

Thanks for the help and patience, folks.

On Oct 16, 2:43 pm, Chris Amico <[EMAIL PROTECTED]> wrote:
> OK, tried all that, got pretty much the same results:
>
> >> import bookmarks
> >>> dir(bookmarks)
>
> ['__builtins__', '__doc__', '__file__', '__name__', '__path__',
> 'models']>>> bookmarks.__file__
>
> '/home/chrisamico/lib/python2.5/bookmarks/__init__.pyc'>>> from bookmarks 
> import templatetags
> >>> dir(templatetags)
>
> ['__builtins__', '__doc__', '__file__', '__name__', '__path__']>>> 
> templatetags.__file__
>
> '/home/chrisamico/lib/python2.5/bookmarks/templatetags/__init__.pyc'>>> from 
> bookmarks.templatetags import bookmark_tags
> > /home/chrisamico/lib/python2.5/bookmarks/templatetags/bookmark_tags.py(4)()
>
> -> from bookmarks.modelsimport Bookmark
> (Pdb) from bookmarks.modelsimport Bookmark
> *** ImportError:Nomodulenamedmodels
>
> Outside the debugger (in python manage.py shell):
>
> >>> from bookmarks.modelsimport Bookmark
>
> So it's only hitting the import error within bookmark_tags.py. Here's
> the directory structure:
>
> *bookmarks
>     __init__.py
>     admin.py
>    models.py
>     views.py
>     *templatetags
>         __init__.py
>         bookmark_tags.py
>
> On Oct 16, 12:56 am, felix <[EMAIL PROTECTED]> wrote:
>
> > oh well.
>
> > check that you have an __init__.py file in the templatetags directory
>
> > try this:
> > in bookmark_tags.py  (and do keep the name that way, or later you will be
> > caught by this)
>
> > right before the import line throw it in into the debugger:
>
> > import pdb; pdb.set_trace()
>
> > in the debugger try:
>
> > >>> import bookmarks
> > >>> dir(bookmarks)
> > >>> bookmarks.__file__
>
> > if you can't even import bookmarks then its not actually on your python
> > path.  remember that your python path needs to include the directory
> > directly above the bookmarks app.
>
> > f;lix
>
> > On Thu, Oct 16, 2008 at 4:53 AM, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > > Tried that. Stillnogood. I renamed the file as bookmark_tags.py and
> > > deleted every .pyc file in the app. Nothing in my templatetags
> > > directory actually compiled--neither __init__.py nor bookmarks.py
> > > (even after being renamed).
>
> > > Like I said before, when I take out the import line (from
> > > bookmarks.modelsimport Bookmark) the library loads (even when called
> > > bookmarks.py) and only hits an error when it tries to access
> > > Bookmark.objects.all().
>
> > > On Oct 15, 6:22 pm, felix <[EMAIL PROTECTED]> wrote:
> > > > this gets me every time.
>
> > > > the error is yes because thetemplatetag is called bookmarks.py
> > > > and its inside amodulecalled bookmarks.py
>
> > > > rename it to bookmarks_tags.py ...
>
> > > > and now 
>
> > > > DELETE THE DAMNED OLD bookmarks.pyc file !
>
> > > > python is still finding the old compiled file.
>
> > > > its happened to me twice already in the exact same fashion.
>
> > > > -f;lix
>
> > > > On Oct 15, 7:17 pm, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > > > > The templatetag file is indeed called bookmarks.py. I thought of that,
> > > > > tried renaming it as bookmark_tags.py, and got the same error. I'll
> > > > > add that the bookmarks app lives on my python path, not in any
> > > > > particular project, since I'm trying to make this as reusable as
> > > > > possible.
>
> > > > > At one point, I tried just removing the line 'from bookmarks.models
> > > > > import Bookmark', and the library loaded, but it hit an error
> > > > > (correctly) when I tried use it, saying Bookmark wasn't defined.
>
> > > > > On Oct 14, 11:45 pm, Daniel Roseman <[EMAIL PROTECTED]>
> > > > > wrote:
>
> > > > > > On Oct 15, 7:38 am, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > > > > > > I have a simple bookmarks model based on the one in James 
> > > > > > > Bennett's
> > >  > > > > > > href="http://code.google.com/p/cab/source/browse/trunk/models.py?
> > > > > > > r=130">Cab application. I'm using a generic relation so it can
> > > > > > > live in its own app and a user can bookmark any object on the site
> > > > > > > (I'm planning on reusing this app on a couple projects). I'm
> > > running
> > > > > > > into a problem creating an {% if_bookmarked %}templatetag.
>
> > > > > > > When I load the tag library I get this error: 'bookmarks' is not a
> > > > > > > valid tag library: Could not loadtemplatelibrary from
> > > > > > > django.templatetags.bookmarks,Nomodulenamedmodels
>
> > > > > > > Here's what the tagmodulelooks like:
>
> > > > > > 
>
> > > > > > > The bookmarking model works fine on its own, and I've gotten the
> > > > > > > functions in thetemplatetag to work in isolation in the
> > > interpreter,
> > > > > > > but when I load the tag library it breaks thetemplate. What am I
> > > 

Re: Custom template tag problem: "No module named models"

2008-10-16 Thread Chris Amico

OK, tried all that, got pretty much the same results:

>> import bookmarks
>>> dir(bookmarks)
['__builtins__', '__doc__', '__file__', '__name__', '__path__',
'models']
>>> bookmarks.__file__
'/home/chrisamico/lib/python2.5/bookmarks/__init__.pyc'
>>> from bookmarks import templatetags
>>> dir(templatetags)
['__builtins__', '__doc__', '__file__', '__name__', '__path__']
>>> templatetags.__file__
'/home/chrisamico/lib/python2.5/bookmarks/templatetags/__init__.pyc'
>>> from bookmarks.templatetags import bookmark_tags
> /home/chrisamico/lib/python2.5/bookmarks/templatetags/bookmark_tags.py(4)()
-> from bookmarks.models import Bookmark
(Pdb) from bookmarks.models import Bookmark
*** ImportError: No module named models

Outside the debugger (in python manage.py shell):

>>> from bookmarks.models import Bookmark
>>>

So it's only hitting the import error within bookmark_tags.py. Here's
the directory structure:

*bookmarks
__init__.py
admin.py
models.py
views.py
*templatetags
__init__.py
bookmark_tags.py



On Oct 16, 12:56 am, felix <[EMAIL PROTECTED]> wrote:
> oh well.
>
> check that you have an __init__.py file in the templatetags directory
>
> try this:
> in bookmark_tags.py  (and do keep the name that way, or later you will be
> caught by this)
>
> right before the import line throw it in into the debugger:
>
> import pdb; pdb.set_trace()
>
> in the debugger try:
>
> >>> import bookmarks
> >>> dir(bookmarks)
> >>> bookmarks.__file__
>
> if you can't even import bookmarks then its not actually on your python
> path.  remember that your python path needs to include the directory
> directly above the bookmarks app.
>
> f;lix
>
> On Thu, Oct 16, 2008 at 4:53 AM, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > Tried that. Still no good. I renamed the file as bookmark_tags.py and
> > deleted every .pyc file in the app. Nothing in my templatetags
> > directory actually compiled--neither __init__.py nor bookmarks.py
> > (even after being renamed).
>
> > Like I said before, when I take out the import line (from
> > bookmarks.models import Bookmark) the library loads (even when called
> > bookmarks.py) and only hits an error when it tries to access
> > Bookmark.objects.all().
>
> > On Oct 15, 6:22 pm, felix <[EMAIL PROTECTED]> wrote:
> > > this gets me every time.
>
> > > the error is yes because the template tag is called bookmarks.py
> > > and its inside a module called bookmarks.py
>
> > > rename it to bookmarks_tags.py ...
>
> > > and now 
>
> > > DELETE THE DAMNED OLD bookmarks.pyc file !
>
> > > python is still finding the old compiled file.
>
> > > its happened to me twice already in the exact same fashion.
>
> > > -f;lix
>
> > > On Oct 15, 7:17 pm, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > > > The templatetag file is indeed called bookmarks.py. I thought of that,
> > > > tried renaming it as bookmark_tags.py, and got the same error. I'll
> > > > add that the bookmarks app lives on my python path, not in any
> > > > particular project, since I'm trying to make this as reusable as
> > > > possible.
>
> > > > At one point, I tried just removing the line 'from bookmarks.models
> > > > import Bookmark', and the library loaded, but it hit an error
> > > > (correctly) when I tried use it, saying Bookmark wasn't defined.
>
> > > > On Oct 14, 11:45 pm, Daniel Roseman <[EMAIL PROTECTED]>
> > > > wrote:
>
> > > > > On Oct 15, 7:38 am, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > > > > > I have a simple bookmarks model based on the one in James Bennett's
> >  > > > > > href="http://code.google.com/p/cab/source/browse/trunk/models.py?
> > > > > > r=130">Cab application. I'm using a generic relation so it can
> > > > > > live in its own app and a user can bookmark any object on the site
> > > > > > (I'm planning on reusing this app on a couple projects). I'm
> > running
> > > > > > into a problem creating an {% if_bookmarked %}templatetag.
>
> > > > > > When I load the tag library I get this error: 'bookmarks' is not a
> > > > > > valid tag library: Could not loadtemplatelibrary from
> > > > > > django.templatetags.bookmarks,Nomodulenamedmodels
>
> > > > > > Here's what the tagmodulelooks like:
>
> > > > > 
>
> > > > > > The bookmarking model works fine on its own, and I've gotten the
> > > > > > functions in thetemplatetag to work in isolation in the
> > interpreter,
> > > > > > but when I load the tag library it breaks thetemplate. What am I
> > > > > > missing here?
>
> > > > > Is the templatetag file itself called bookmarks.py, by any chance? If
> > > > > so, the code may be trying to import that rather than the top-level
> > > > > bookmarks directory. Try renaming the file, although I would also
> > > > > recommend using full paths when importing (ie from
> > > > > projectname.bookmarks.models).
> > > > > --
> > > > > DR
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to

Re: Custom template tag problem: "No module named models"

2008-10-16 Thread felix
oh well.

check that you have an __init__.py file in the templatetags directory

try this:
in bookmark_tags.py  (and do keep the name that way, or later you will be
caught by this)

right before the import line throw it in into the debugger:

import pdb; pdb.set_trace()

in the debugger try:

>>> import bookmarks
>>> dir(bookmarks)
>>> bookmarks.__file__

if you can't even import bookmarks then its not actually on your python
path.  remember that your python path needs to include the directory
directly above the bookmarks app.

f;lix


On Thu, Oct 16, 2008 at 4:53 AM, Chris Amico <[EMAIL PROTECTED]> wrote:

>
> Tried that. Still no good. I renamed the file as bookmark_tags.py and
> deleted every .pyc file in the app. Nothing in my templatetags
> directory actually compiled--neither __init__.py nor bookmarks.py
> (even after being renamed).
>
> Like I said before, when I take out the import line (from
> bookmarks.models import Bookmark) the library loads (even when called
> bookmarks.py) and only hits an error when it tries to access
> Bookmark.objects.all().
>
>
>
> On Oct 15, 6:22 pm, felix <[EMAIL PROTECTED]> wrote:
> > this gets me every time.
> >
> > the error is yes because the template tag is called bookmarks.py
> > and its inside a module called bookmarks.py
> >
> > rename it to bookmarks_tags.py ...
> >
> > and now 
> >
> > DELETE THE DAMNED OLD bookmarks.pyc file !
> >
> > python is still finding the old compiled file.
> >
> > its happened to me twice already in the exact same fashion.
> >
> > -f;lix
> >
> > On Oct 15, 7:17 pm, Chris Amico <[EMAIL PROTECTED]> wrote:
> >
> > > The templatetag file is indeed called bookmarks.py. I thought of that,
> > > tried renaming it as bookmark_tags.py, and got the same error. I'll
> > > add that the bookmarks app lives on my python path, not in any
> > > particular project, since I'm trying to make this as reusable as
> > > possible.
> >
> > > At one point, I tried just removing the line 'from bookmarks.models
> > > import Bookmark', and the library loaded, but it hit an error
> > > (correctly) when I tried use it, saying Bookmark wasn't defined.
> >
> > > On Oct 14, 11:45 pm, Daniel Roseman <[EMAIL PROTECTED]>
> > > wrote:
> >
> > > > On Oct 15, 7:38 am, Chris Amico <[EMAIL PROTECTED]> wrote:
> >
> > > > > I have a simple bookmarks model based on the one in James Bennett's
>  > > > > href="http://code.google.com/p/cab/source/browse/trunk/models.py?
> > > > > r=130">Cab application. I'm using a generic relation so it can
> > > > > live in its own app and a user can bookmark any object on the site
> > > > > (I'm planning on reusing this app on a couple projects). I'm
> running
> > > > > into a problem creating an {% if_bookmarked %}templatetag.
> >
> > > > > When I load the tag library I get this error: 'bookmarks' is not a
> > > > > valid tag library: Could not loadtemplatelibrary from
> > > > > django.templatetags.bookmarks,Nomodulenamedmodels
> >
> > > > > Here's what the tagmodulelooks like:
> >
> > > > 
> >
> > > > > The bookmarking model works fine on its own, and I've gotten the
> > > > > functions in thetemplatetag to work in isolation in the
> interpreter,
> > > > > but when I load the tag library it breaks thetemplate. What am I
> > > > > missing here?
> >
> > > > Is the templatetag file itself called bookmarks.py, by any chance? If
> > > > so, the code may be trying to import that rather than the top-level
> > > > bookmarks directory. Try renaming the file, although I would also
> > > > recommend using full paths when importing (ie from
> > > > projectname.bookmarks.models).
> > > > --
> > > > DR
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2008-10-15 Thread Chris Amico

Tried that. Still no good. I renamed the file as bookmark_tags.py and
deleted every .pyc file in the app. Nothing in my templatetags
directory actually compiled--neither __init__.py nor bookmarks.py
(even after being renamed).

Like I said before, when I take out the import line (from
bookmarks.models import Bookmark) the library loads (even when called
bookmarks.py) and only hits an error when it tries to access
Bookmark.objects.all().



On Oct 15, 6:22 pm, felix <[EMAIL PROTECTED]> wrote:
> this gets me every time.
>
> the error is yes because the template tag is called bookmarks.py
> and its inside a module called bookmarks.py
>
> rename it to bookmarks_tags.py ...
>
> and now 
>
> DELETE THE DAMNED OLD bookmarks.pyc file !
>
> python is still finding the old compiled file.
>
> its happened to me twice already in the exact same fashion.
>
> -f;lix
>
> On Oct 15, 7:17 pm, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > The templatetag file is indeed called bookmarks.py. I thought of that,
> > tried renaming it as bookmark_tags.py, and got the same error. I'll
> > add that the bookmarks app lives on my python path, not in any
> > particular project, since I'm trying to make this as reusable as
> > possible.
>
> > At one point, I tried just removing the line 'from bookmarks.models
> > import Bookmark', and the library loaded, but it hit an error
> > (correctly) when I tried use it, saying Bookmark wasn't defined.
>
> > On Oct 14, 11:45 pm, Daniel Roseman <[EMAIL PROTECTED]>
> > wrote:
>
> > > On Oct 15, 7:38 am, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > > > I have a simple bookmarks model based on the one in James Bennett's  > > > href="http://code.google.com/p/cab/source/browse/trunk/models.py?
> > > > r=130">Cab application. I'm using a generic relation so it can
> > > > live in its own app and a user can bookmark any object on the site
> > > > (I'm planning on reusing this app on a couple projects). I'm running
> > > > into a problem creating an {% if_bookmarked %}templatetag.
>
> > > > When I load the tag library I get this error: 'bookmarks' is not a
> > > > valid tag library: Could not loadtemplatelibrary from
> > > > django.templatetags.bookmarks,Nomodulenamedmodels
>
> > > > Here's what the tagmodulelooks like:
>
> > > 
>
> > > > The bookmarking model works fine on its own, and I've gotten the
> > > > functions in thetemplatetag to work in isolation in the interpreter,
> > > > but when I load the tag library it breaks thetemplate. What am I
> > > > missing here?
>
> > > Is the templatetag file itself called bookmarks.py, by any chance? If
> > > so, the code may be trying to import that rather than the top-level
> > > bookmarks directory. Try renaming the file, although I would also
> > > recommend using full paths when importing (ie from
> > > projectname.bookmarks.models).
> > > --
> > > DR
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2008-10-15 Thread felix


this gets me every time.

the error is yes because the template tag is called bookmarks.py
and its inside a module called bookmarks.py

rename it to bookmarks_tags.py ...

and now 

DELETE THE DAMNED OLD bookmarks.pyc file !

python is still finding the old compiled file.

its happened to me twice already in the exact same fashion.

-f;lix


On Oct 15, 7:17 pm, Chris Amico <[EMAIL PROTECTED]> wrote:
> The templatetag file is indeed called bookmarks.py. I thought of that,
> tried renaming it as bookmark_tags.py, and got the same error. I'll
> add that the bookmarks app lives on my python path, not in any
> particular project, since I'm trying to make this as reusable as
> possible.
>
> At one point, I tried just removing the line 'from bookmarks.models
> import Bookmark', and the library loaded, but it hit an error
> (correctly) when I tried use it, saying Bookmark wasn't defined.
>
> On Oct 14, 11:45 pm, Daniel Roseman <[EMAIL PROTECTED]>
> wrote:
>
> > On Oct 15, 7:38 am, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > > I have a simple bookmarks model based on the one in James Bennett's  > > href="http://code.google.com/p/cab/source/browse/trunk/models.py?
> > > r=130">Cab application. I'm using a generic relation so it can
> > > live in its own app and a user can bookmark any object on the site
> > > (I'm planning on reusing this app on a couple projects). I'm running
> > > into a problem creating an {% if_bookmarked %}templatetag.
>
> > > When I load the tag library I get this error: 'bookmarks' is not a
> > > valid tag library: Could not loadtemplatelibrary from
> > > django.templatetags.bookmarks,Nomodulenamedmodels
>
> > > Here's what the tagmodulelooks like:
>
> > 
>
> > > The bookmarking model works fine on its own, and I've gotten the
> > > functions in thetemplatetag to work in isolation in the interpreter,
> > > but when I load the tag library it breaks thetemplate. What am I
> > > missing here?
>
> > Is the templatetag file itself called bookmarks.py, by any chance? If
> > so, the code may be trying to import that rather than the top-level
> > bookmarks directory. Try renaming the file, although I would also
> > recommend using full paths when importing (ie from
> > projectname.bookmarks.models).
> > --
> > DR
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2008-10-15 Thread Chris Amico

Wish it were that easy. The app is installed, and it works everywhere
else. If I take out the {% load bookmarks %} from the template, the
rest of the app works fine. I have a view that bookmarks an object,
and it checks if a user has bookmarked that object first.

This is how I did it in the view (part of another app--a database of
online news tools):

def bookmark_tool(request, category_id, tool_id):
"Bookmarks a tool"
user = get_object_or_404(User, pk=request.user.id)
tool = get_object_or_404(Tool,
 category__slug__iexact=category_id,
 slug__iexact=tool_id)
b_list = [b.content_object for b in user.bookmark_set.all()]
if tool not in b_list:
Bookmark.objects.create(content_object=tool, user=user)
return HttpResponseRedirect(tool.get_absolute_url())

And that works exactly as it should.

On Oct 15, 11:21 am, RyanP <[EMAIL PROTECTED]> wrote:
> Seems like the problem's got to be with the "from bookmarks.models
> import Bookmark" line.
>
> The "No module named models" part of your error message suggests that
> Django doesn't know about your bookmarks/models.py ... if that app is
> on your Pyton path, any chance that it's just not listed in your
> INSTALLED_APPS?
>
> On Oct 15, 10:17 am, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > The templatetag file is indeed called bookmarks.py. I thought of that,
> > tried renaming it as bookmark_tags.py, and got the same error. I'll
> > add that the bookmarks app lives on my python path, not in any
> > particular project, since I'm trying to make this as reusable as
> > possible.
>
> > At one point, I tried just removing the line 'from bookmarks.models
> > import Bookmark', and the library loaded, but it hit an error
> > (correctly) when I tried use it, saying Bookmark wasn't defined.
>
> > On Oct 14, 11:45 pm, Daniel Roseman <[EMAIL PROTECTED]>
> > wrote:
>
> > > On Oct 15, 7:38 am, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > > > I have a simple bookmarks model based on the one in James Bennett's  > > > href="http://code.google.com/p/cab/source/browse/trunk/models.py?
> > > > r=130">Cab application. I'm using a generic relation so it can
> > > > live in its own app and a user can bookmark any object on the site
> > > > (I'm planning on reusing this app on a couple projects). I'm running
> > > > into a problem creating an {% if_bookmarked %}templatetag.
>
> > > > When I load the tag library I get this error: 'bookmarks' is not a
> > > > valid tag library: Could not loadtemplatelibrary from
> > > > django.templatetags.bookmarks,Nomodulenamedmodels
>
> > > > Here's what the tagmodulelooks like:
>
> > > 
>
> > > > The bookmarking model works fine on its own, and I've gotten the
> > > > functions in thetemplatetag to work in isolation in the interpreter,
> > > > but when I load the tag library it breaks thetemplate. What am I
> > > > missing here?
>
> > > Is the templatetag file itself called bookmarks.py, by any chance? If
> > > so, the code may be trying to import that rather than the top-level
> > > bookmarks directory. Try renaming the file, although I would also
> > > recommend using full paths when importing (ie from
> > > projectname.bookmarks.models).
> > > --
> > > DR
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2008-10-15 Thread RyanP

Seems like the problem's got to be with the "from bookmarks.models
import Bookmark" line.

The "No module named models" part of your error message suggests that
Django doesn't know about your bookmarks/models.py ... if that app is
on your Pyton path, any chance that it's just not listed in your
INSTALLED_APPS?

On Oct 15, 10:17 am, Chris Amico <[EMAIL PROTECTED]> wrote:
> The templatetag file is indeed called bookmarks.py. I thought of that,
> tried renaming it as bookmark_tags.py, and got the same error. I'll
> add that the bookmarks app lives on my python path, not in any
> particular project, since I'm trying to make this as reusable as
> possible.
>
> At one point, I tried just removing the line 'from bookmarks.models
> import Bookmark', and the library loaded, but it hit an error
> (correctly) when I tried use it, saying Bookmark wasn't defined.
>
> On Oct 14, 11:45 pm, Daniel Roseman <[EMAIL PROTECTED]>
> wrote:
>
> > On Oct 15, 7:38 am, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > > I have a simple bookmarks model based on the one in James Bennett's  > > href="http://code.google.com/p/cab/source/browse/trunk/models.py?
> > > r=130">Cab application. I'm using a generic relation so it can
> > > live in its own app and a user can bookmark any object on the site
> > > (I'm planning on reusing this app on a couple projects). I'm running
> > > into a problem creating an {% if_bookmarked %}templatetag.
>
> > > When I load the tag library I get this error: 'bookmarks' is not a
> > > valid tag library: Could not loadtemplatelibrary from
> > > django.templatetags.bookmarks,Nomodulenamedmodels
>
> > > Here's what the tagmodulelooks like:
>
> > 
>
> > > The bookmarking model works fine on its own, and I've gotten the
> > > functions in thetemplatetag to work in isolation in the interpreter,
> > > but when I load the tag library it breaks thetemplate. What am I
> > > missing here?
>
> > Is the templatetag file itself called bookmarks.py, by any chance? If
> > so, the code may be trying to import that rather than the top-level
> > bookmarks directory. Try renaming the file, although I would also
> > recommend using full paths when importing (ie from
> > projectname.bookmarks.models).
> > --
> > DR
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2008-10-15 Thread Chris Amico

The templatetag file is indeed called bookmarks.py. I thought of that,
tried renaming it as bookmark_tags.py, and got the same error. I'll
add that the bookmarks app lives on my python path, not in any
particular project, since I'm trying to make this as reusable as
possible.

At one point, I tried just removing the line 'from bookmarks.models
import Bookmark', and the library loaded, but it hit an error
(correctly) when I tried use it, saying Bookmark wasn't defined.


On Oct 14, 11:45 pm, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Oct 15, 7:38 am, Chris Amico <[EMAIL PROTECTED]> wrote:
>
> > I have a simple bookmarks model based on the one in James Bennett's  > href="http://code.google.com/p/cab/source/browse/trunk/models.py?
> > r=130">Cab application. I'm using a generic relation so it can
> > live in its own app and a user can bookmark any object on the site
> > (I'm planning on reusing this app on a couple projects). I'm running
> > into a problem creating an {% if_bookmarked %}templatetag.
>
> > When I load the tag library I get this error: 'bookmarks' is not a
> > valid tag library: Could not loadtemplatelibrary from
> > django.templatetags.bookmarks,Nomodulenamedmodels
>
> > Here's what the tagmodulelooks like:
>
> 
>
> > The bookmarking model works fine on its own, and I've gotten the
> > functions in thetemplatetag to work in isolation in the interpreter,
> > but when I load the tag library it breaks thetemplate. What am I
> > missing here?
>
> Is the templatetag file itself called bookmarks.py, by any chance? If
> so, the code may be trying to import that rather than the top-level
> bookmarks directory. Try renaming the file, although I would also
> recommend using full paths when importing (ie from
> projectname.bookmarks.models).
> --
> DR
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2008-10-15 Thread Daniel Roseman

On Oct 15, 7:38 am, Chris Amico <[EMAIL PROTECTED]> wrote:
> I have a simple bookmarks model based on the one in James Bennett's  href="http://code.google.com/p/cab/source/browse/trunk/models.py?
> r=130">Cab application. I'm using a generic relation so it can
> live in its own app and a user can bookmark any object on the site
> (I'm planning on reusing this app on a couple projects). I'm running
> into a problem creating an {% if_bookmarked %} template tag.
>
> When I load the tag library I get this error: 'bookmarks' is not a
> valid tag library: Could not load template library from
> django.templatetags.bookmarks, No module named models
>
> Here's what the tag module looks like:
>



> The bookmarking model works fine on its own, and I've gotten the
> functions in the template tag to work in isolation in the interpreter,
> but when I load the tag library it breaks the template. What am I
> missing here?

Is the templatetag file itself called bookmarks.py, by any chance? If
so, the code may be trying to import that rather than the top-level
bookmarks directory. Try renaming the file, although I would also
recommend using full paths when importing (ie from
projectname.bookmarks.models).
--
DR
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2008-10-15 Thread Malcolm Tredinnick


On Wed, 2008-10-15 at 01:08 -0700, bruno desthuilliers wrote:
[...]
> FWIW, I just don't understand why each an every example in the
> Django's manual insists on using this projectname.appname scheme.

"Insists" is a rather strong word, since nowhere does it say "do this or
else". Also, out of all the code fragments in all the documentation,
very few actually talk about app or project imports at all. So let's
keep things a little bit in perspective. :-)

We take patches to change that kind of stuff if you want to make it
better.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag problem: "No module named models"

2008-10-15 Thread bruno desthuilliers



On 15 oct, 08:45, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
(snip otherwise sound advises)

> although I would also
> recommend using full paths when importing (ie from
> projectname.bookmarks.models).

No. *Don't*. If you do so, imports will break when renaming the
 directory or trying to reuse the bookmark app in another
project.

FWIW, I just don't understand why each an every example in the
Django's manual insists on using this projectname.appname scheme.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag

2008-01-13 Thread Alessandro Ronchi

2008/1/13, Alex Koshelev <[EMAIL PROTECTED]>:
>
> 'templatetags' instead of 'templatetag'
> '{% load feed_import %}' instead of '{% load feedimport %}'

My error wasn't that (I made a mistake writing here). It was a failed
import inside the tag, and that caused the error without the correct
error writing in debug mode, because the import in django source
catches the importError.

Thanks to all.

-- 
Alessandro Ronchi
Skype: aronchi
http://www.alessandroronchi.net - Il mio sito personale
http://www.soasi.com - Sviluppo Software e Sistemi Open Source

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag

2008-01-13 Thread Alex Koshelev

'templatetags' instead of 'templatetag'
'{% load feed_import %}' instead of '{% load feedimport %}'

On 13 янв, 19:47, Alessandro <[EMAIL PROTECTED]> wrote:
> I'm trying to create a custom template tag. I've added a feedimport
> app in my project, added it on my installed apps, and inside it I've
> created a templatetag directory with a file feed_import.py
>
> Both feedimport and templatetag dirs have an empty __init__.py file.
> I'm trying to load my feedimport with
> {% load feedimport %} in a template, but it says:
>
> TemplateSyntaxError: 'feed_import' is not a valid tag library: Could
> not load template library from django.templatetags.feed_import, No
> module named feedparser
>
> What's wrong?
>
> ~~
> This is the source code of my feed_import.py file:
>
> import urllib, os, time, datetime, feedparser
> from django.conf import settings
> from django import template
>
> register = template.Library()
>
> @register.inclusion_tag('feedimport/pull_feed.html')
> def pull_feed(feed_url, posts_to_show=5, cache_expires=30):
> CACHE_FILE = ''.join([settings.CACHE_FOLDER,
> template.defaultfilters.slugify(feed_url), '.cache'])
> try:
> cache_age = os.stat(CACHE_FILE)[8]
> except: #if file doesn't exist, make sure it gets created
> cache_age = 0
> #is cache expired? default 30 minutes (30*60)
> if (cache_age + cache_expires*60 < time.time()):
> try: #refresh cache
> urllib.urlretrieve(feed_url,CACHE_FILE)
> except IOError: #if downloading fails, proceed using cached file
> pass
> #load feed from cache
> feed = feedparser.parse(open(CACHE_FILE))
> posts = []
> for i in range(posts_to_show):
> pub_date = feed['entries'][i].updated_parsed
> published = datetime.date(pub_date[0], pub_date[1], pub_date[2] )
> posts.append({
> 'title': feed['entries'][i].title,
> 'summary': feed['entries'][i].summary,
> 'link': feed['entries'][i].link,
> 'date': published,
> })
> return {'posts': posts}
>
> --
> Alessandro Ronchi
> Skype: aronchihttp://www.alessandroronchi.net- Il mio sito 
> personalehttp://www.soasi.com- Sviluppo Software e Sistemi Open Source
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag

2008-01-13 Thread Alexey Moskvin

The correct directory for your tags is "templatetags", not
"templatetag"

On 13 янв, 19:47, Alessandro <[EMAIL PROTECTED]> wrote:
> I'm trying to create a custom template tag. I've added a feedimport
> app in my project, added it on my installed apps, and inside it I've
> created a templatetag directory with a file feed_import.py
>
> Both feedimport and templatetag dirs have an empty __init__.py file.
> I'm trying to load my feedimport with
> {% load feedimport %} in a template, but it says:
>
> TemplateSyntaxError: 'feed_import' is not a valid tag library: Could
> not load template library from django.templatetags.feed_import, No
> module named feedparser
>
> What's wrong?
>
> ~~
> This is the source code of my feed_import.py file:
>
> import urllib, os, time, datetime, feedparser
> from django.conf import settings
> from django import template
>
> register = template.Library()
>
> @register.inclusion_tag('feedimport/pull_feed.html')
> def pull_feed(feed_url, posts_to_show=5, cache_expires=30):
> CACHE_FILE = ''.join([settings.CACHE_FOLDER,
> template.defaultfilters.slugify(feed_url), '.cache'])
> try:
> cache_age = os.stat(CACHE_FILE)[8]
> except: #if file doesn't exist, make sure it gets created
> cache_age = 0
> #is cache expired? default 30 minutes (30*60)
> if (cache_age + cache_expires*60 < time.time()):
> try: #refresh cache
> urllib.urlretrieve(feed_url,CACHE_FILE)
> except IOError: #if downloading fails, proceed using cached file
> pass
> #load feed from cache
> feed = feedparser.parse(open(CACHE_FILE))
> posts = []
> for i in range(posts_to_show):
> pub_date = feed['entries'][i].updated_parsed
> published = datetime.date(pub_date[0], pub_date[1], pub_date[2] )
> posts.append({
> 'title': feed['entries'][i].title,
> 'summary': feed['entries'][i].summary,
> 'link': feed['entries'][i].link,
> 'date': published,
> })
> return {'posts': posts}
>
> --
> Alessandro Ronchi
> Skype: aronchihttp://www.alessandroronchi.net- Il mio sito 
> personalehttp://www.soasi.com- Sviluppo Software e Sistemi Open Source
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: (solved) Re: Custom template tag and filters in resolve_variable

2007-12-06 Thread Manakel

Nice Nice, i 'll add this to my django reference sheet

On Dec 6, 3:34 pm, Empty <[EMAIL PROTECTED]> wrote:
> Nice info.  This was just asked on the IRC channel a couple nights
> ago.  I'll be sure to pass it on.
>
> Michael Trier
> blog.michaeltrier.com
>
> On Dec 5, 2007 7:09 PM, Michal Ludvig <[EMAIL PROTECTED]> wrote:
>
>
>
> > Michal Ludvig wrote:
>
> > > for the project I'm working on I needed to create a custom template tag,
> > > call it 'mytag'.
>
> > > If I use it as {% mytag something %} everything goes fine (where
> > > 'something' is a string passed to the template).
> > > However I can't add any filters to that 'something'. As soon as I do:
> > > {% mytag something|upper %}
> > > I get an exception:
> > >   VariableDoesNotExist at /test/
> > >   Failed lookup for key [something|upper]
>
> > > That leads to a code in MytagNode.render() method:
> > >   actual_message = resolve_variable(self.message, context)
> > > where self.message is the argument passed to the macro, in this case
> > > it's a string 'something|upper'.
>
> > > Is there an easy way to run all the attached filters in MytagNode?
>
> > For the record:
> > There is a FilterExpression class in django.template that does exactly
> > what I need. So for the tag implementation, instead of:
>
> > ===
> > from django.template import resolve_variable
>
> > @register.tag
> > def mytag(parser, token):
> > tag_name, message = token.split_contents()
> > [...]
> > return MytagNode(message)
>
> > class MytagNode(template.Node):
> > [...]
> > def render(self, context):
> > actual_message = resolve_variable(self.message, context)
> > [...]
> > ===
>
> > I do it like this:
>
> > ===
> > from django.template import FilterExpression
>
> > @register.tag
> > def mytag(parser, token):
> > [...]
> > filter_expression = FilterExpression(message, parser)
> > return MytagNode(filter_expression)
>
> > class MytagNode(template.Node):
> > [...]
> > def render(self, context):
> > actual_message = self.filter_expression.resolve(context)
> > [...]
> > ===
>
> > The filter_expression.resolve(context) runs all the filters attached to
> > the variable and things work as expected. The 'parser' argument even
> > makes it aware of custom filters loaded through {% load ... %} tags.
>
> > Lesson learned, note taken.
>
> > Michal
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: (solved) Re: Custom template tag and filters in resolve_variable

2007-12-06 Thread Empty

Nice info.  This was just asked on the IRC channel a couple nights
ago.  I'll be sure to pass it on.

Michael Trier
blog.michaeltrier.com

On Dec 5, 2007 7:09 PM, Michal Ludvig <[EMAIL PROTECTED]> wrote:
>
> Michal Ludvig wrote:
>
> > for the project I'm working on I needed to create a custom template tag,
> > call it 'mytag'.
> >
> > If I use it as {% mytag something %} everything goes fine (where
> > 'something' is a string passed to the template).
> > However I can't add any filters to that 'something'. As soon as I do:
> > {% mytag something|upper %}
> > I get an exception:
> >   VariableDoesNotExist at /test/
> >   Failed lookup for key [something|upper]
> >
> > That leads to a code in MytagNode.render() method:
> >   actual_message = resolve_variable(self.message, context)
> > where self.message is the argument passed to the macro, in this case
> > it's a string 'something|upper'.
> >
> > Is there an easy way to run all the attached filters in MytagNode?
>
> For the record:
> There is a FilterExpression class in django.template that does exactly
> what I need. So for the tag implementation, instead of:
>
> ===
> from django.template import resolve_variable
>
> @register.tag
> def mytag(parser, token):
> tag_name, message = token.split_contents()
> [...]
> return MytagNode(message)
>
> class MytagNode(template.Node):
> [...]
> def render(self, context):
> actual_message = resolve_variable(self.message, context)
> [...]
> ===
>
> I do it like this:
>
> ===
> from django.template import FilterExpression
>
> @register.tag
> def mytag(parser, token):
> [...]
> filter_expression = FilterExpression(message, parser)
> return MytagNode(filter_expression)
>
> class MytagNode(template.Node):
> [...]
> def render(self, context):
> actual_message = self.filter_expression.resolve(context)
> [...]
> ===
>
> The filter_expression.resolve(context) runs all the filters attached to
> the variable and things work as expected. The 'parser' argument even
> makes it aware of custom filters loaded through {% load ... %} tags.
>
> Lesson learned, note taken.
>
> Michal
>
>
>
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



(solved) Re: Custom template tag and filters in resolve_variable

2007-12-05 Thread Michal Ludvig

Michal Ludvig wrote:

> for the project I'm working on I needed to create a custom template tag,
> call it 'mytag'.
> 
> If I use it as {% mytag something %} everything goes fine (where
> 'something' is a string passed to the template).
> However I can't add any filters to that 'something'. As soon as I do:
> {% mytag something|upper %}
> I get an exception:
>   VariableDoesNotExist at /test/
>   Failed lookup for key [something|upper]
> 
> That leads to a code in MytagNode.render() method:
>   actual_message = resolve_variable(self.message, context)
> where self.message is the argument passed to the macro, in this case
> it's a string 'something|upper'.
> 
> Is there an easy way to run all the attached filters in MytagNode?

For the record:
There is a FilterExpression class in django.template that does exactly 
what I need. So for the tag implementation, instead of:

===
from django.template import resolve_variable

@register.tag
def mytag(parser, token):
tag_name, message = token.split_contents()
[...]
return MytagNode(message)

class MytagNode(template.Node):
[...]
def render(self, context):
actual_message = resolve_variable(self.message, context)
[...]
===

I do it like this:

===
from django.template import FilterExpression

@register.tag
def mytag(parser, token):
[...]
filter_expression = FilterExpression(message, parser)
return MytagNode(filter_expression)

class MytagNode(template.Node):
[...]
def render(self, context):
actual_message = self.filter_expression.resolve(context)
[...]
===

The filter_expression.resolve(context) runs all the filters attached to 
the variable and things work as expected. The 'parser' argument even 
makes it aware of custom filters loaded through {% load ... %} tags.

Lesson learned, note taken.

Michal



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag and filters in resolve_variable

2007-12-05 Thread Michal Ludvig

Rune Bromer wrote:
> On Dec 5, 2007, at 11:59 AM, Michal Ludvig wrote:
> 
>> Hi all,
>>
>> for the project I'm working on I needed to create a custom template  
>> tag,
>> call it 'mytag'.
>>
>> If I use it as {% mytag something %} everything goes fine (where
>> 'something' is a string passed to the template).
>> However I can't add any filters to that 'something'. As soon as I do:
>> {% mytag something|upper %}
>> I get an exception:
>>  VariableDoesNotExist at /test/
>>  Failed lookup for key [something|upper]
>>
>> That leads to a code in MytagNode.render() method:
>>  actual_message = resolve_variable(self.message, context)
>> where self.message is the argument passed to the macro, in this case
>> it's a string 'something|upper'.
>>
>> Is there an easy way to run all the attached filters in MytagNode?
> 
> Look at the "filter" templatetag [1]. You must do something like
> 
> {% filter upper %} {% mytag something %} {% endfilter %}

That seems to run the whole output of mytag through the filter. I just
need the parameter itself filtered. In reality mytag gets two arguments,
'label' and 'value' and spits out a few lines of HTML. It displays some
user profile information. The value of each property may need to be
filtered differently, e.g. if it's a dollar amount I want to attach my
filter '|dollarformat' that turns an integer like 1000 to a more
readable "$1,000". For other properties I may want other filters. In any
case I only need to filter the argument, not the tag output.

I could probably do something like message.split("|") and run the
filters (if any) manually. That is, import them from
django.template.defaultfilters and pass the output of resolve_variable
through them. But what if the filter in question is imported from a
non-default tag library? How do I find what to import then?

BTW Wouldn't it be more user-friendly to resolve the variable and run
all the filters yet before the custom tag gets called?

Michal




--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag and filters in resolve_variable

2007-12-05 Thread Rune Bromer

On Dec 5, 2007, at 11:59 AM, Michal Ludvig wrote:

> Hi all,
>
> for the project I'm working on I needed to create a custom template  
> tag,
> call it 'mytag'.
>
> If I use it as {% mytag something %} everything goes fine (where
> 'something' is a string passed to the template).
> However I can't add any filters to that 'something'. As soon as I do:
> {% mytag something|upper %}
> I get an exception:
>   VariableDoesNotExist at /test/
>   Failed lookup for key [something|upper]
>
> That leads to a code in MytagNode.render() method:
>   actual_message = resolve_variable(self.message, context)
> where self.message is the argument passed to the macro, in this case
> it's a string 'something|upper'.
>
> Is there an easy way to run all the attached filters in MytagNode?

Look at the "filter" templatetag [1]. You must do something like

{% filter upper %} {% mytag something %} {% endfilter %}

[1] http://www.djangoproject.com/documentation/templates/#filter

-- 
Rune Bromer
Coniuro ApS
Tlf: +45 60 64 59 83
Email: [EMAIL PROTECTED]








--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: custom template tag

2007-07-06 Thread [EMAIL PROTECTED]

You might want to have a look at this, if not to use it, at least to
see how the templatetags are done: 
http://code.google.com/p/django-template-utils/

On Jul 6, 4:39 pm, dystopia <[EMAIL PROTECTED]> wrote:
> Hi,
>  I've been trying to get something together to
> see if I can get to grips with writing my own tempalte tags. In the
> end I came up with something
> like this (so far):
>
> from myproject.shop.models import Product
> from django import template
>
> register = template.Library()
>
> def get_latest_products(parser, token):
> # Get list of products by date.
> latestProducts = Product.objects.all().order_by('pub_date')[:5]
> return latestProductsNode()
>
> class latestProductsNode(template.Node):
>
> def __init__(self):
> # Get list of products by date.
> self.latestProducts =
> Product.objects.all().order_by('pub_date')[:5]
>
> def render(self, context):
> return self.latestProducts
>
> register.tag('latest_products', get_latest_products)
>
> Something tells me this is not the way to go about what I want to do.
> All I want is a tag that outputs a list of  the five most recent
> products.
>
> Anyone care to give me any pointers on this?
>
> Thanks,
>
> James


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom Template Tag - What do I need in my actual template?

2006-10-13 Thread MerMer

Tim,

Many thanks - that works a treat.  I was getting myself very confused
about where and how to use the context.

Cheers

MerMer


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom Template Tag - What do I need in my actual template?

2006-10-13 Thread Tim Shaffer

Your code looks valid as it is right now. The get_latest_polls function
should return a QuerySet of the three latest polls.

When you call this function it will get the polls and assign the
QuerySet to the "polls" variable for use in your template.

In order to display the polls, you would need to do something like
this:

{% get_latest_polls 3 %}

{% for poll in polls %}
{{ polls.question }}
{% endfor %}


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag in FlatPage

2006-08-11 Thread Michal

Hello Adrian,
thank you for the link to documentation. I was missing __init__.py in my 
templatetags directory.

Have a nice day
Michal

Adrian Holovaty wrote:
> On 8/11/06, Michal <[EMAIL PROTECTED]> wrote:
>> Hello,
>> I would like use my custom filter function inside Flatpage template. How
>> could I do this?
>>
>> If I try to load my custom tags model ({% load cust_template_tags %}) I
>> get this error:
> 
> Hi Michal,
> 
> A flatpage template is no different from any other template -- the
> template system is decoupled from the rest of the framework, and
> therefore it doesn't care which application is using it (flatpages or
> not).
> 
> In your particular case, make sure your custom template tag libraries
> are registered in INSTALLED_APPS, per the documentation:
> 
> http://www.djangoproject.com/documentation/templates_python/#extending-the-template-system
> 
> Adrian
> 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag in FlatPage

2006-08-11 Thread Adrian Holovaty

On 8/11/06, Michal <[EMAIL PROTECTED]> wrote:
> Hello,
> I would like use my custom filter function inside Flatpage template. How
> could I do this?
>
> If I try to load my custom tags model ({% load cust_template_tags %}) I
> get this error:

Hi Michal,

A flatpage template is no different from any other template -- the
template system is decoupled from the rest of the framework, and
therefore it doesn't care which application is using it (flatpages or
not).

In your particular case, make sure your custom template tag libraries
are registered in INSTALLED_APPS, per the documentation:

http://www.djangoproject.com/documentation/templates_python/#extending-the-template-system

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag (?) help

2006-04-03 Thread Chase

I knew it was something stupid and easy. I was just following the wrong
part of the tutorial.

Thanks,
Chase


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Custom template tag (?) help

2006-04-03 Thread limodou

On 4/4/06, Chase <[EMAIL PROTECTED]> wrote:
>
> Hi all
>
> I've read the docs and looked through a few examples, but I can't
> figure this out: I want to create the equivalent a global template
> variable -- a string representing the current outdoor temperature -- to
> display atop every page without having to render it again and again in
> every view. It seems the solution is to create a custom template tag,
> but I can't figure out how to create a tag that will simply return a
> value from a database. Effectively something like this:
>
> def get_temp(parser):
> return tempNode()
>
> class tempNode(template.Node):
> def render(self, context):
> return weather.get_temp(id__exact=1)
>
> Obviously this is wrong. Problem is I have no idea how to do this right
> or even whether custom template tags are the best way to solve this.
> Would anyone mind giving me a hand? I'm a little new to Django, and I'm
> especially new to this part of it, so any mercy would be appreciated.
>
> Thanks,
> Chase
>
>

You can find a fullly example in

http://www.djangoproject.com/documentation/templates_python/#setting-a-variable-in-the-context


--
I like python!
My Blog: http://www.donews.net/limodou
My Django Site: http://www.djangocn.org
NewEdit Maillist: http://groups.google.com/group/NewEdit

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---