Thursday, May 29, 2014

Re: reverse function

The functions reverse and reverse_lazy are useful for figuring out the paths from labels. If you or someone else changes the urlconf in the future, your app uses the new paths without difficulty.

If you have in your urls.py

url(r'^home/$', views.home, name='home'),
url(r'^specifics/(?P<poll_id>\d+)/$', views.detail, name='detail'),

Then in your views.py you have:

print reverse('home')
# prints /home/

print reverse('detail', args=[12])
# prints /detail/12/

As for render_to_response, it is still there and everybody still uses it.

K

On Thursday, May 29, 2014 3:46:21 AM UTC-7, joy wrote:
Good morning everyone, i was using django as of django 0.9 and now i'm looking again in the tutorial and i have to say that a lot has changed. I undestand che basics (even if i cannot understan why in the tutorial they use the context and doesn'use any more "render_to_response") but however what i cannot understand is che function "reverse" which is used in the views, what is its use? San you explain it to me while i'm going through the tutorial again to understand? Thank you. Agnese

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ba68138e-d004-4fa7-bfdd-b530337c0be7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment