Sunday, May 12, 2013

Re: HttpResponse.has_header

On Sat, May 11, 2013 at 9:04 PM, Larry Martell <larry.martell@gmail.com> wrote:
> On Sat, May 11, 2013 at 9:08 AM, Masklinn <masklinn@masklinn.net> wrote:
>>
>> On 2013-05-11, at 17:01 , Larry Martell wrote:
>>
>>> On Sat, May 11, 2013 at 8:23 AM, Masklinn <masklinn@masklinn.net> wrote:
>>>> On 2013-05-11, at 15:57 , Larry Martell wrote:
>>>>>
>>>>> Yes, that is what I did. This is not in my urlconf. It's in a view
>>>>> function. I replaced:
>>>>>
>>>>> return direct_to_template(request, template)
>>>>>
>>>>> by:
>>>>>
>>>>> return TemplateView.as_view(template_name=template)
>>>>>
>>>>> Is that not correct?
>>>>
>>>> Indeed not, `TemplateView.as_view(template)` is roughly equivalent to
>>>> `functools.partial(direct_to_template, template=template)`: it's only
>>>> one half of the operation, which returns a callable replying to
>>>> requests.
>>>>
>>>> You need something along the lines of `TemplateView.as_view(template)(request)`
>>>
>>> I appreciate all the assistance. I tried that and got:
>>>
>>> TypeError: as_view() takes exactly 1 argument (2 given)
>>>
>>
>> Oh yeah, you need to pass it as the keyword argument "template_name"
>> sorry about that. Basically take your code and add "(request)" at the
>> end.
>>
>> If the current request is a GET obviously.
>
> Thanks. That got me further along. I don't understand that syntax
> though. Never see that before.
>
> But now I'm having a NoReverseMatch issue that I don't get in 1.4.
> I'll have to dig into that on Monday.

Being OCD I couldn't wait until Monday ;-) The issue was that when I
was using direct_to_template I was passing in extra_context. You can't
do that with TemplateView. I had to subclass TemplateView and provide
my own get_context_data method. Now all I have to do is change the 52
usages of {% url ... %} to quote the first argument.

--
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+unsubscribe@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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate