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())

On Wednesday, December 5, 2018 at 11:55:08 PM UTC-5, Sourajit Mohanty wrote:
>
> 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??
>
> On Thu 6 Dec, 2018, 9:13 AM Pankaj Kumar <pan...@turiyan.com <javascript:> 
> wrote:
>
>> Try using regular expression  (?P<id>[0-9]+)
>>  similar to this:
>>
>> url(r'^music/(?P<id>[0-9]+)/newsongs$', views.your_view_function())
>>
>>
>> cheers!
>>
>> On 12/6/18, Sourajit Mohanty <smohan...@gmail.com <javascript:>> wrote:
>> > I am working with Class based Views..so I dont think this is gonna work
>> >
>> > On Thu 6 Dec, 2018, 2:33 AM shiva kumar <kannamshi...@gmail.com 
>> <javascript:>
>> > wrote:
>> >
>> >> Use
>> >>
>> >> <int: Id> in place of number
>> >>
>> >> An add extra parameter in views which u will relate this to
>> >>
>> >> On Thu 6 Dec, 2018 2:18 am Sourajit Mohanty <smohan...@gmail.com 
>> <javascript:>
>> >> wrote:
>> >>
>> >>> 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 <javascript:>.
>> >>> To post to this group, send email to django...@googlegroups.com 
>> <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/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 <javascript:>.
>> >> To post to this group, send email to django...@googlegroups.com 
>> <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/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 <javascript:>.
>> > To post to this group, send email to django...@googlegroups.com 
>> <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/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 <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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.

Reply via email to