The only place you can have a redirect is in the view, you are
treating the inclusion tag as if it was a separate view to be rendered
and then included in the page, however this isn't how it works, the
best way to do this would be to use the inclusion tag to simply place
the form on the page, and then place all the processing in a specific
view,

On Mar 6, 8:26 am, A Hampton <[EMAIL PROTECTED]> wrote:
> I must be missing something, because I'm unable to redirect from a
> template tag.
>
> On my page, I want a form.  There is only one box for input -- page
> number.  The visitor enters a page number, it jumps to that page of
> the site.
>
> Instead of having to write it in every view, I wrote an
> inclusion_tag.  The box shows up, but it won't redirect.  Please, look
> over the code below.  Let me know what I'm doing wrong.  I tried all
> day yesterday to get it to work, and another hour this morning.  It's
> not like my site will die without it, I just want to know how to do
> it.  If you know, please share.
>
> #######################
>
> forms.py:
>
> from django import newforms as forms
>
> class PageJumpForm(forms.Form):
>     page = forms.IntegerField(min_value=0, label='Page Number',)
>
> ########################
>
> formtags.py
>
> from django import template
> from aaron.forms.forms import PageJumpForm
> from django.http import HttpResponseRedirect
>
> register = template.Library()
>
> @register.inclusion_tag('pagejump.html')
> def pagejump(request):
>     the_type = type(request)
>     if request.method == 'POST':
>         form = PageJumpForm(request.POST)
>         if form.is_valid():
>             page=form.cleaned_data['page']
>             return HttpResponseRedirect('/page%s/' % page)
>     else:
>         form = PageJumpForm()
>     return {'form':form}
>
> ############################
>
> pagejump.html
>
> <form action="." method="post">
>     <table>
>         {{ form.as_table }}
>     </table>
>     <p>
>         <input type="submit" value="Submit" />
>     </p>
> </form>
>
> ############################
>
> Any input would be great.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to