Re: Adding context data to a TemplateView?

2015-07-22 Thread bobby
An additional point, if you want to be able to use the view more 
generically (be able to pass in custom context from your urls.py), I've 
done the following:

class StaticPageView(TemplateView):
context = None

def get_context_data(self, **kwargs):
context = super(StaticPageView, self).get_context_data(**kwargs)
context.update(self.context or {})
return context

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cc05af47-b6ae-4050-bbd9-6a8958db502e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding context data to a TemplateView?

2013-04-04 Thread Dan Gentry
Roy, I agree with Fallen that a subclass of TemplateView is required here. 
 I have used this technique often.  Dan

class MyTemplateView(TemplateView):
template_name = 'my_template.html'

def get_context_data(self, **kwargs):
context = super(MyTemplateView, self).get_context_data(**kwargs)
context['custom_variable'] = u'my special data'
return context

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Adding context data to a TemplateView?

2013-04-04 Thread Fallen Flint
Take a look at 
https://docs.djangoproject.com/en/1.4/topics/generic-views-migration/#extra-context
There's no way for provide an extra_context to a TemplateView. You need to 
subclass TemplateView and re-implement get_context_data in the way 
described in aforementioned topic.

On Monday, April 23, 2012 1:20:09 AM UTC+4, Roy Smith wrote:
>
> I'm using a generic TemplateView (django-1.4), but I want to be able to 
> add something to the context.  Is that possible?
>
> The docs at 
> https://docs.djangoproject.com/en/1.4/topics/generic-views/#adding-extra-context
>  talk 
> about "an extra optional parameter, extra_context", but I don't get what 
> they're trying to explain.  I tried the obvious:
>
> url(r'^about$',
> TemplateView.as_view(template_name='legal_ipsum/about.html',
>  extra_context={'pagename': 'about'})
> ),
>
> in my urls.py file, but that just raises: "TemplateView() received an 
> invalid keyword 'extra_context'".  What am I missing here?
>
> --
> Roy Smith
> r...@panix.com 
>
>
>  
>

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Adding context data to a TemplateView?

2012-04-22 Thread Buddy Lindsey, Jr.

This should help you out with adding extra context to TemplateView

http://godjango.com/15-class-based-views-part-1-templateview-and-redirectview/

Roy Smith wrote:


I'm using a generic TemplateView (django-1.4), but I want to be able
to add something to the context. Is that possible?

The docs at
https://docs.djangoproject.com/en/1.4/topics/generic-views/#adding-extra-context 


talk about "an extra optional parameter, extra_context", but I don't
get what they're trying to explain. I tried the obvious:

url(r'^about$',
TemplateView.as_view(template_name='legal_ipsum/about.html',
extra_context={'pagename': 'about'})
),

in my urls.py file, but that just raises: "TemplateView() received an
invalid keyword 'extra_context'". What am I missing here?

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


--
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: Adding context data to a TemplateView?

2012-04-22 Thread Ejah
Oh, and an extra set of curly braces:
url(r'^about$',
TemplateView.as_view(template_name='legal_ipsum/about.html',
{"extra_content":{"pagename":"about"}})),

On Apr 22, 11:28 pm, Ejah  wrote:
> Quotes around extra_context
> HTH
>
> On Apr 22, 11:20 pm, Roy Smith  wrote:
>
>
>
>
>
>
>
> > I'm using a generic TemplateView (django-1.4), but I want to be able to add 
> > something to the context.  Is that possible?
>
> > The docs 
> > athttps://docs.djangoproject.com/en/1.4/topics/generic-views/#adding-ex...about
> >  "an extra optional parameter, extra_context", but I don't get what they're 
> > trying to explain.  I tried the obvious:
>
> >     url(r'^about$',
> >     TemplateView.as_view(template_name='legal_ipsum/about.html',
> >                          extra_context={'pagename': 'about'})
> >         ),
>
> > in my urls.py file, but that just raises: "TemplateView() received an 
> > invalid keyword 'extra_context'".  What am I missing here?
>
> > --
> > Roy Smith
> > r...@panix.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Adding context data to a TemplateView?

2012-04-22 Thread Ejah
Quotes around extra_context
HTH

On Apr 22, 11:20 pm, Roy Smith  wrote:
> I'm using a generic TemplateView (django-1.4), but I want to be able to add 
> something to the context.  Is that possible?
>
> The docs 
> athttps://docs.djangoproject.com/en/1.4/topics/generic-views/#adding-ex...talk
>  about "an extra optional parameter, extra_context", but I don't get what 
> they're trying to explain.  I tried the obvious:
>
>     url(r'^about$',
>     TemplateView.as_view(template_name='legal_ipsum/about.html',
>                          extra_context={'pagename': 'about'})
>         ),
>
> in my urls.py file, but that just raises: "TemplateView() received an invalid 
> keyword 'extra_context'".  What am I missing here?
>
> --
> Roy Smith
> r...@panix.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Adding context data to a TemplateView?

2012-04-22 Thread Roy Smith
I'm using a generic TemplateView (django-1.4), but I want to be able to add 
something to the context.  Is that possible?

The docs at 
https://docs.djangoproject.com/en/1.4/topics/generic-views/#adding-extra-context
 talk about "an extra optional parameter, extra_context", but I don't get what 
they're trying to explain.  I tried the obvious:

url(r'^about$',
TemplateView.as_view(template_name='legal_ipsum/about.html',
 extra_context={'pagename': 'about'})
),

in my urls.py file, but that just raises: "TemplateView() received an invalid 
keyword 'extra_context'".  What am I missing here?

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