On Thu, May 16, 2013 at 2:59 PM, Masklinn <[email protected]> wrote: > > On 2013-05-16, at 22:41 , Larry Martell wrote: > >> On Thu, May 16, 2013 at 2:37 PM, Masklinn <[email protected]> wrote: >>> >>> On 2013-05-16, at 22:22 , Larry Martell wrote: >>> >>>> On Sat, May 11, 2013 at 8:23 AM, Masklinn <[email protected]> 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 am running into this same problem with RedirectView. In 1.4 I had a >>>> view that was doing: >>>> >>>> return redirect_to(request, new_report.url) >>>> >>>> I changed it to: >>>> >>>> return RedirectView.as_view(url=new_report.url) >>>> >>>> and it's blowing up with: >>>> >>>> Traceback: >>>> File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" >>>> in get_response >>>> 187. response = middleware_method(request, response) >>>> File >>>> "/Library/Python/2.7/site-packages/django/contrib/sessions/middleware.py" >>>> in process_response >>>> 26. patch_vary_headers(response, ('Cookie',)) >>>> File "/Library/Python/2.7/site-packages/django/utils/cache.py" in >>>> patch_vary_headers >>>> 142. if response.has_header('Vary'): >>>> >>>> I tried doing something similar to what you suggested with >>>> TemplateView, but that didn't work: >>>> >>>> RedirectView.as_view(url=new_report.url)(request) >>>> *** TypeError: a float is required >>> >>> Do you have a full traceback? >> >> That is the full traceback I get the browser. >> >>> Does `new_report.url` contain format metacharacters such as %f? >> >> Yes: >> >> (Pdb) print new_report.url >> /report/CDSEM/MeasurementData/?date_time=3%2F4%2F10&submit_preview=Generate+Report&group=&target_name=&tool_ids=15&recipe=&ep=&roi_name=&lot=&field_6=Date+Time&field_7=Bottom&field_4=Ep&field_5=Lot&field_2=Target&field_3=Recipe&field_1=Tool > > Looks like you probably need to escape (double) the % signs: > https://docs.djangoproject.com/en/1.5/ref/class-based-views/base/#django.views.generic.base.RedirectView > >> The given URL may contain dictionary-style string formatting, which >> will be interpolated against the parameters captured in the URL. Because >> keyword interpolation is always done (even if no arguments are passed >> in), any "%" characters in the URL must be written as "%%" so that >> Python will convert them to a single percent sign on output.
Tried this, got the same error. > But really, while I might somewhat see the point of using > TemplateView[0] I don't see the point of using RedirectView in that > manner, why not just return an HttpResponseRedirect[3]? I don't know I didn't write this and the original developer is gone. I'm just trying to upgrade to 1.5, and based on what I read at https://docs.djangoproject.com/en/1.4/topics/generic-views-migration/ I changed all the calls to redirect_to to RedirectView. I changed this to HttpResponseRedirect as you suggested and it's working. Thanks once again. > Class-based views are really for using in URL mappings (potentially > custom subclasses), not for using in your own view functions. > > [0] Still, it would probably be simpler to use TemplateResponse[1] > directly, or render_to render_to_response[2] if it's sufficient > [1] > https://docs.djangoproject.com/en/dev/ref/template-response/#templateresponse-objects > [2] > https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#django.shortcuts.render_to_response > [3] > https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponseRedirect -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.

