Python Forum
get_absolute_url function not working?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get_absolute_url function not working?
#1
Hi,

So I am using django 2.2.7 and following videos on youtube for learning Python Django.

My models.py file consists of a class for an Album object and a class for a Song object.
Inside this models.py file I have declared a function called get_absolute_url (please see the attached image models).

I want to allow the user of the website to be able to create a new Album object by filling in a form and then clicking submit. Therefore, I have created this form - its consists of two separate codes shown in album_form.jpg and form-template.jpg. They just enter values for for input fields album, artist, genre and logo. Then they click submit. I have attached an image of what the actual forum looks like on the web.

However, the issue I am having is that clicking submit does not seem to do anything at all. The least I was expecting was to be redirected to the url written inside the get_absolute_url function which is "music:detail" passing in the primary key that gets created when new object of Album is made. The "music:detail" is the name for the url and it is path('<int:pk>/', views.DetailView.as_view(), name='detail')

Does anyone know why this is happening? Some people have mentioned changing the action in form code but the tutorials I am following leave the action as blank i.e. action="" so that's why I left it as blank. Not sure if that is the issue?

Thanks,

Attached Files

Thumbnail(s)
               
Reply


Messages In This Thread
get_absolute_url function not working? - by mp3909 - Jul-11-2020, 07:03 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020