Re: [Solved] Re: Django chokes on template blocks?

2006-08-17 Thread Sean Schertell

Thanks Malcom :-)


On Aug 18, 2006, at 10:58 AM, Malcolm Tredinnick wrote:

>
> On Fri, 2006-08-18 at 09:51 +0900, Sean Schertell wrote:
>> Yay!!!  It works like magic!
>>
>> Would anyone be so kind as to reveal the mysteries of this "Context
>> ()" function? I'd love to know what this code is doing and why it
>> fixes my problem.
>
> Context() isn't a function, it's creating a class instance
> (django.template.context.Context is the class involved). The Context
> class acts like a dictionary and a stack: you can push a new empty
> dictionary onto the stack, fill it with keys and values, use it a bit
> and then pop it off later to get back to your previous dictionary
> instance. This feature is used in a few places, block overriding being
> one of them.
>
> Regards,
> Malcolm
>
>
>
> >
>
>

  DataFly.Net  
Complete Web Services
http://www.datafly.net


--~--~-~--~~~---~--~~
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: [Solved] Re: Django chokes on template blocks?

2006-08-17 Thread Malcolm Tredinnick

On Fri, 2006-08-18 at 09:51 +0900, Sean Schertell wrote:
> Yay!!!  It works like magic!
> 
> Would anyone be so kind as to reveal the mysteries of this "Context 
> ()" function? I'd love to know what this code is doing and why it  
> fixes my problem.

Context() isn't a function, it's creating a class instance
(django.template.context.Context is the class involved). The Context
class acts like a dictionary and a stack: you can push a new empty
dictionary onto the stack, fill it with keys and values, use it a bit
and then pop it off later to get back to your previous dictionary
instance. This feature is used in a few places, block overriding being
one of them.

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



[Solved] Re: Django chokes on template blocks?

2006-08-17 Thread Sean Schertell

Yay!!!  It works like magic!

Would anyone be so kind as to reveal the mysteries of this "Context 
()" function? I'd love to know what this code is doing and why it  
fixes my problem.

Thanks again everyone -- especially you Adrian H. -- you're too much!

:-D

Sean


On Aug 18, 2006, at 8:34 AM, Adrian Holovaty wrote:

>
> On 8/17/06, Sean Schertell <[EMAIL PROTECTED]> wrote:
>> --- modulalib/views.py ---
>> http://rafb.net/paste/results/fzWg1g26.html
>
> The problem is in the staticpages() function. Specifically, the
> default value for the context_processor argument is None -- which
> means you're passing None to t.render(). Instead, t.render() needs to
> be passed a Context object. Add these lines as the first lines within
> the function:
>
> if context_processors is None:
> context_processors = Context()
>
> Also, make sure to do a "from django.template import Context" atop  
> the module.
>
> 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: Django chokes on template blocks?

2006-08-17 Thread Jeremy Dunck

On 8/17/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
> The render() method takes a template.Context object, not a dictionary.
> You want this:
>
> ind.render(template.Context())

Bah, sorry.  :-/

--~--~-~--~~~---~--~~
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: Django chokes on template blocks?

2006-08-17 Thread Adrian Holovaty

On 8/17/06, Jeremy Dunck <[EMAIL PROTECTED]> wrote:
> >>> ind.render({})
> Traceback (most recent call last):
> [...]
> TemplateSyntaxError: Caught an exception while rendering: 'dict' object has 
> no a
> ttribute 'push'

The render() method takes a template.Context object, not a dictionary.
You want this:

ind.render(template.Context())

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: Django chokes on template blocks?

2006-08-17 Thread Jeremy Dunck

On 8/17/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
> I suspect the problem is in how you're loading the template and
> rendering it. Can you paste us the code in your view that loads the
> template, passes it a context and renders it? If you're not sure what
> code I'm talking about, just paste us your whole view, if that's
> possible.

I'm reproing here.

index.html:

{% extends "basex.html" %}

{% block content %}
hi

{% endblock %}

basex.html (just to ensure not picking up from somewhere surprising)
===
{% block content %} {% endblock %}
===

C:\temp\priv\djangotest>python manage.py shell
Python 2.4.1 (#65, Jun 20 2005, 17:01:55) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import settings
>>> settings.TEMPLATE_LOADERS
('django.template.loaders.filesystem.load_template_source', 'django.template.loa
ders.app_directories.load_template_source')
>>> settings.TEMPLATE_DIRS
('C:/temp/priv/djangotest/test/templates',)
>>> from django.template import loader
>>> ind  = loader.get_template('index.html')
>>> ind.render({})
Traceback (most recent call last):
  File "", line 1, in ?
  File "c:\temp\priv\django\django\template\__init__.py", line 155, in render
return self.nodelist.render(context)
  File "c:\temp\priv\django\django\template\__init__.py", line 688, in render
bits.append(self.render_node(node, context))
  File "c:\temp\priv\django\django\template\__init__.py", line 706, in render_no
de
result = node.render(context)
  File "c:\temp\priv\django\django\template\loader_tags.py", line 82, in render
return compiled_parent.render(context)
  File "c:\temp\priv\django\django\template\__init__.py", line 155, in render
return self.nodelist.render(context)
  File "c:\temp\priv\django\django\template\__init__.py", line 688, in render
bits.append(self.render_node(node, context))
  File "c:\temp\priv\django\django\template\__init__.py", line 716, in render_no
de
raise wrapped
TemplateSyntaxError: Caught an exception while rendering: 'dict' object has no a
ttribute 'push'

Original Traceback (most recent call last):
  File "c:\temp\priv\django\django\template\__init__.py", line 706, in render_no
de
result = node.render(context)
  File "c:\temp\priv\django\django\template\loader_tags.py", line 19, in render
context.push()
AttributeError: 'dict' object has no attribute 'push'

>>>

..I'm at a loss.

--~--~-~--~~~---~--~~
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: Django chokes on template blocks?

2006-08-17 Thread Adrian Holovaty

On 8/17/06, Sean Schertell <[EMAIL PROTECTED]> wrote:
> I'm trying to get my first django project off the ground but I've hit
> snag that I can't seem to get around. I've made a base.html template
> and an index.html template that extends the base (pretty standard
> stuff I think).
>
> But django barfs up this error:
> -
> AttributeError at /
> 'NoneType' object has no attribute 'push'
> -

Hey Sean,

I suspect the problem is in how you're loading the template and
rendering it. Can you paste us the code in your view that loads the
template, passes it a context and renders it? If you're not sure what
code I'm talking about, just paste us your whole view, if that's
possible.

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: Django chokes on template blocks?

2006-08-17 Thread Adrian Holovaty

On 8/17/06, Hawkeye <[EMAIL PROTECTED]> wrote:
> So... I'm relatively new to Django, but...
>
> You have "{% block content %}{% endblock %}" (note: this is from the
> image posted)
>
> My suggestion would be to try putting a space between the tags.  I
> don't have Django in front of me, so I can't test this, but it looks
> like it's expecting content in the block tag and trying to perform an
> operation on it.  Since there is no content, it might be getting
> confused.

This comment is inaccurate. {% block %} tags are not required to have
any space between them. "{% block content %}{% endblock %}" -- with no
space -- is perfectly valid.

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: Django chokes on template blocks?

2006-08-17 Thread Sean Schertell

>> But django barfs up this error:
>> -
>> AttributeError at /
>> 'NoneType' object has no attribute 'push'
>> -
>
> Let's see the index template.  :)

Thanks jeremy, here's the index template:
http://rafb.net/paste/results/X5LCeK54.html

Sean




--~--~-~--~~~---~--~~
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: Django chokes on template blocks?

2006-08-17 Thread Jeremy Dunck

On 8/17/06, Sean Schertell <[EMAIL PROTECTED]> wrote:
> But django barfs up this error:
> -
> AttributeError at /
> 'NoneType' object has no attribute 'push'
> -

Let's see the index template.  :)

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



Django chokes on template blocks?

2006-08-17 Thread Sean Schertell

Hi guys,

I'm trying to get my first django project off the ground but I've hit  
snag that I can't seem to get around. I've made a base.html template  
and an index.html template that extends the base (pretty standard  
stuff I think).

But django barfs up this error:
-
AttributeError at /
'NoneType' object has no attribute 'push'
-

Huh?

Here's a screenshot that should clarify:
http://datafly.net/django-error.png

Anybody got any idea why I can't use blocks in my templates? What am  
I doing wrong?

:-)

Sean

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