Friday, February 3, 2012

Re: Need help regarding url patterns

On Feb 3, 2:50 pm, ankitrocks <aapkaankit...@gmail.com> wrote:
> Hi.
> Thanks for replying.
>
> The reason  I used login/logout multiple times in the urls.py because
> i was unable to redirect from polls/03/logout to polls/login. When I
> am using href="../logout" , it works but sometimes when I am in
> level-2 in doesnt work.
> Please ignore the parameters of poll id in login/logout. Its just that
> I was trying something and forgot to remove the code.
>
> Now I went through reverse thing. I didnt get an idea about how do I
> redirect from a logout link in any page to polls/logout and also the
> url in the address bar should change. Please help me out.

I don't get what "url in address bar should change". So, the answer
might not be to your question...

Basically, you want to use the url template tag, from the
documentation:
{% url path.to.some_view v1 v2 %}

In your case, this would be something like:
<a href="{% url polls.views.logout_view %}">Logout</a>
That is, you are fetching the url for polls.views.logout_view without
any arguments. Detail view for poll no 1 would be something like this:
<a href="{% url polls.views.detail poll_id=1 %}">View poll No. 1</a>

This is very basic introduction to Django's url resolving. And the
given code might actually not work correctly, haven't tested it. It
should contain the idea, though. I suggest you use some time learning
more about the url resolving system, it is time well spent.

You do not need (or want) to have multiple URLs defined for the
logout_view. That is, remove the logout_view mapping with poll_id
argument.

- Anssi

--
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.

No comments:

Post a Comment