Discussion:
How to extract a number from a url
(too old to reply)
Sourajit Mohanty
2018-12-05 20:48:20 UTC
Permalink
I want to extract the number from this url 'music/6/newsongs/' so that I can use that number to redirect it to another page..
How can I do that??
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8512424b-8a0e-40a2-92f0-2e9d4f8995a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
shiva kumar
2018-12-05 21:02:38 UTC
Permalink
Use

<int: Id> in place of number

An add extra parameter in views which u will relate this to
Post by Sourajit Mohanty
I want to extract the number from this url 'music/6/newsongs/' so that I
can use that number to redirect it to another page..
How can I do that??
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/8512424b-8a0e-40a2-92f0-2e9d4f8995a1%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMsYeuHeAbwr6SgozHM4wxkqMFiWhLnQc6ODy75FHm0qBs9O0Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Sourajit Mohanty
2018-12-05 21:12:07 UTC
Permalink
I am working with Class based Views..so I dont think this is gonna work
Post by shiva kumar
Use
<int: Id> in place of number
An add extra parameter in views which u will relate this to
Post by Sourajit Mohanty
I want to extract the number from this url 'music/6/newsongs/' so that I
can use that number to redirect it to another page..
How can I do that??
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/8512424b-8a0e-40a2-92f0-2e9d4f8995a1%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAMsYeuHeAbwr6SgozHM4wxkqMFiWhLnQc6ODy75FHm0qBs9O0Q%40mail.gmail.com
<https://groups.google.com/d/msgid/django-users/CAMsYeuHeAbwr6SgozHM4wxkqMFiWhLnQc6ODy75FHm0qBs9O0Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMh8ciYOg36bQ%3DP%2BLvuuvoCpDaO7C1bMH2O8nPaP6YFeBeYk%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Pankaj Kumar
2018-12-06 03:43:03 UTC
Permalink
Try using regular expression (?P<id>[0-9]+)
similar to this:

url(r'^music/(?P<id>[0-9]+)/newsongs$', views.your_view_function())


cheers!
Post by Sourajit Mohanty
I am working with Class based Views..so I dont think this is gonna work
Post by shiva kumar
Use
<int: Id> in place of number
An add extra parameter in views which u will relate this to
Post by Sourajit Mohanty
I want to extract the number from this url 'music/6/newsongs/' so that I
can use that number to redirect it to another page..
How can I do that??
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/8512424b-8a0e-40a2-92f0-2e9d4f8995a1%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAMsYeuHeAbwr6SgozHM4wxkqMFiWhLnQc6ODy75FHm0qBs9O0Q%40mail.gmail.com
<https://groups.google.com/d/msgid/django-users/CAMsYeuHeAbwr6SgozHM4wxkqMFiWhLnQc6ODy75FHm0qBs9O0Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAMh8ciYOg36bQ%3DP%2BLvuuvoCpDaO7C1bMH2O8nPaP6YFeBeYk%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMAa5dOeDZYaujTXhOn%3DsGEU%3D_aDkgQ3mKrJyNEoBvbAB%3D9qhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Sourajit Mohanty
2018-12-06 04:54:05 UTC
Permalink
I am using Model forms..

class CreateSong(CreateView)
model=Song
fields=['song_title']

So this class is gonna call the model Song class..how can i pass the
album_id??
Post by Pankaj Kumar
Try using regular expression (?P<id>[0-9]+)
url(r'^music/(?P<id>[0-9]+)/newsongs$', views.your_view_function())
cheers!
Post by Sourajit Mohanty
I am working with Class based Views..so I dont think this is gonna work
Post by shiva kumar
Use
<int: Id> in place of number
An add extra parameter in views which u will relate this to
Post by Sourajit Mohanty
I want to extract the number from this url 'music/6/newsongs/' so that I
can use that number to redirect it to another page..
How can I do that??
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/8512424b-8a0e-40a2-92f0-2e9d4f8995a1%40googlegroups.com
Post by Sourajit Mohanty
Post by shiva kumar
Post by Sourajit Mohanty
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups
Post by Sourajit Mohanty
Post by shiva kumar
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an
Post by Sourajit Mohanty
Post by shiva kumar
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAMsYeuHeAbwr6SgozHM4wxkqMFiWhLnQc6ODy75FHm0qBs9O0Q%40mail.gmail.com
Post by Sourajit Mohanty
Post by shiva kumar
<
https://groups.google.com/d/msgid/django-users/CAMsYeuHeAbwr6SgozHM4wxkqMFiWhLnQc6ODy75FHm0qBs9O0Q%40mail.gmail.com?utm_medium=email&utm_source=footer
Post by Sourajit Mohanty
Post by shiva kumar
.
For more options, visit https://groups.google.com/d/optout.
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAMh8ciYOg36bQ%3DP%2BLvuuvoCpDaO7C1bMH2O8nPaP6YFeBeYk%3DA%40mail.gmail.com
.
Post by Sourajit Mohanty
For more options, visit https://groups.google.com/d/optout.
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAMAa5dOeDZYaujTXhOn%3DsGEU%3D_aDkgQ3mKrJyNEoBvbAB%3D9qhQ%40mail.gmail.com
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMh8cib4qJHNEKvNXNjZG_qX12iwDdBy%2Bux%3DTv6BoOoEOiOiww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Jason
2018-12-06 13:01:49 UTC
Permalink
you have to set up the URL with it in your urls.py to map to the view
method.

what that does is tells django you want the regex in the url path you
defined to be the parameter you send to the view method

pk_url_kwarg = 'pk'

set that in your view, and ensure the url definition you have maps to `pk`
like

path('music/<int:album_id>/newsongs$', views.CreateSong.as_view())
Post by Sourajit Mohanty
I am using Model forms..
class CreateSong(CreateView)
model=Song
fields=['song_title']
So this class is gonna call the model Song class..how can i pass the
album_id??
Post by Pankaj Kumar
Try using regular expression (?P<id>[0-9]+)
url(r'^music/(?P<id>[0-9]+)/newsongs$', views.your_view_function())
cheers!
Post by Sourajit Mohanty
I am working with Class based Views..so I dont think this is gonna work
<javascript:>
Post by Sourajit Mohanty
Post by shiva kumar
Use
<int: Id> in place of number
An add extra parameter in views which u will relate this to
<javascript:>
Post by Sourajit Mohanty
Post by shiva kumar
Post by Sourajit Mohanty
I want to extract the number from this url 'music/6/newsongs/' so
that
Post by Sourajit Mohanty
Post by shiva kumar
Post by Sourajit Mohanty
I
can use that number to redirect it to another page..
How can I do that??
--
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
<javascript:>.
Post by Sourajit Mohanty
Post by shiva kumar
Post by Sourajit Mohanty
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/8512424b-8a0e-40a2-92f0-2e9d4f8995a1%40googlegroups.com
Post by Sourajit Mohanty
Post by shiva kumar
Post by Sourajit Mohanty
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups
Post by Sourajit Mohanty
Post by shiva kumar
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an
<javascript:>.
Post by Sourajit Mohanty
Post by shiva kumar
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAMsYeuHeAbwr6SgozHM4wxkqMFiWhLnQc6ODy75FHm0qBs9O0Q%40mail.gmail.com
Post by Sourajit Mohanty
Post by shiva kumar
<
https://groups.google.com/d/msgid/django-users/CAMsYeuHeAbwr6SgozHM4wxkqMFiWhLnQc6ODy75FHm0qBs9O0Q%40mail.gmail.com?utm_medium=email&utm_source=footer
Post by Sourajit Mohanty
Post by shiva kumar
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups
Post by Sourajit Mohanty
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an
<javascript:>.
Post by Sourajit Mohanty
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAMh8ciYOg36bQ%3DP%2BLvuuvoCpDaO7C1bMH2O8nPaP6YFeBeYk%3DA%40mail.gmail.com
.
Post by Sourajit Mohanty
For more options, visit https://groups.google.com/d/optout.
--
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
<javascript:>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAMAa5dOeDZYaujTXhOn%3DsGEU%3D_aDkgQ3mKrJyNEoBvbAB%3D9qhQ%40mail.gmail.com
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f6f1983a-6659-4f9e-af10-ce58d0752af9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sourajit Mohanty
2018-12-06 14:24:13 UTC
Permalink
But how do I access the pk_url_kwarg(ie. the album_id) in the respective
model??
I have a model class Song and I need 2 access the album_id in the
get_absolute_url()
Post by Jason
you have to set up the URL with it in your urls.py to map to the view
method.
what that does is tells django you want the regex in the url path you
defined to be the parameter you send to the view method
pk_url_kwarg = 'pk'
set that in your view, and ensure the url definition you have maps to
`pk` like
path('music/<int:album_id>/newsongs$', views.CreateSong.as_view())
Post by Sourajit Mohanty
I am using Model forms..
class CreateSong(CreateView)
model=Song
fields=['song_title']
So this class is gonna call the model Song class..how can i pass the
album_id??
Post by Pankaj Kumar
Try using regular expression (?P<id>[0-9]+)
url(r'^music/(?P<id>[0-9]+)/newsongs$', views.your_view_function())
cheers!
Post by Sourajit Mohanty
I am working with Class based Views..so I dont think this is gonna work
Post by shiva kumar
Use
<int: Id> in place of number
An add extra parameter in views which u will relate this to
Post by Sourajit Mohanty
I want to extract the number from this url 'music/6/newsongs/' so
that
Post by Sourajit Mohanty
Post by shiva kumar
Post by Sourajit Mohanty
I
can use that number to redirect it to another page..
How can I do that??
--
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
Post by Sourajit Mohanty
Post by shiva kumar
Post by Sourajit Mohanty
an
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/8512424b-8a0e-40a2-92f0-2e9d4f8995a1%40googlegroups.com
Post by Sourajit Mohanty
Post by shiva kumar
Post by Sourajit Mohanty
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups
Post by Sourajit Mohanty
Post by shiva kumar
"Django users" group.
To unsubscribe from this group and stop receiving emails from it,
send an
Post by Sourajit Mohanty
Post by shiva kumar
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAMsYeuHeAbwr6SgozHM4wxkqMFiWhLnQc6ODy75FHm0qBs9O0Q%40mail.gmail.com
Post by Sourajit Mohanty
Post by shiva kumar
<
https://groups.google.com/d/msgid/django-users/CAMsYeuHeAbwr6SgozHM4wxkqMFiWhLnQc6ODy75FHm0qBs9O0Q%40mail.gmail.com?utm_medium=email&utm_source=footer
Post by Sourajit Mohanty
Post by shiva kumar
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups
Post by Sourajit Mohanty
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an
Post by Sourajit Mohanty
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAMh8ciYOg36bQ%3DP%2BLvuuvoCpDaO7C1bMH2O8nPaP6YFeBeYk%3DA%40mail.gmail.com
.
Post by Sourajit Mohanty
For more options, visit https://groups.google.com/d/optout.
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAMAa5dOeDZYaujTXhOn%3DsGEU%3D_aDkgQ3mKrJyNEoBvbAB%3D9qhQ%40mail.gmail.com
.
For more options, visit https://groups.google.com/d/optout.
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/f6f1983a-6659-4f9e-af10-ce58d0752af9%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/f6f1983a-6659-4f9e-af10-ce58d0752af9%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMh8ciYPCASwd_r__%2BG%2Bht5hx1HfSQ2m4EvcTYGHRdTWaNpkxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...