Monday, October 24, 2011

Re: redirect problems

On Mon, Oct 24, 2011 at 12:34 PM, nicolas HERSOG <n.hersog@gmail.com> wrote:
> Hi everyone,
> I digged more but i'm still stuck.
> I understood that i have to use namespaceURL.
> So i modified my url.py this way :
> from myAppFront.views import article
>     url (r'^article/(?P<id>\d+)/$',
>         myAppFront.views.article,
>         name='article'),

Note: this doesn't namespace it, it gives it the explicit name
'article'. If you gave it a name like 'myApp:article' it would be in
the myApp namespace, or if the entire urlconf is included in the main
urlconf with a namespace, but you don't mention doing that.

> and this is my addComment view :
> ...
>     #return HttpResponseRedirect(reverse('myAppFront.views.article',
> args=(id,)))
>     return HttpResponseRedirect(reverse('myAppFront.views.article',
> kwargs={'id': id}))

Having named it, you can (and should) use the name when reversing the
URL, not the view definition, eg:

return HttpResponseRedirect(reverse('article', args=(id,)))

You could also use the dict syntax as well, I prefer the tuple version
for simple single argument URLs like this.

Hope that helps

Cheers

Tom

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate