Look at the new Boston.com he did a tutorial on exactly this issue Rob 203-671-6514 Sent from my mobile device, please excuse the typos.
> On May 25, 2019, at 7:25 PM, Yoo <[email protected]> wrote: > > Maybe try album__id (two underscores)? Or try album_title as defined in the > Album model. I also advise not to expose your primary key in the URL. If the > above did not work, check Django documentation: > https://docs.djangoproject.com/en/2.2/topics/http/urls/ > >> On Saturday, May 25, 2019 at 2:46:58 PM UTC-4, Anchal Agarwal wrote: >> I am currently working on a django project in which there is a music app. >> The models of this app contains Albums and Songs. I want to return the http >> response when the django receives a url as /music/712 , here 712 is the >> object id. >> Please help me out in resolving the issue.Thanks in advance. >> >> Here are my files. Here album_id will be the id of the object. >> models.py >> from django.db import models >> >> class Album(models.Model): >> artist = models.CharField(max_length=250) >> album_title = models.CharField(max_length=500) >> genre=models.CharField(max_length=100) >> album_logo = models.CharField(max_length=1000) >> >> def __str__(self): >> return self.album_title >> >> class Song(models.Model): >> album= models.ForeignKey(Album, on_delete=models.CASCADE) >> file_type= models.CharField(max_length=10) >> song_title = models.CharField(max_length=250) >> >> views.py >> from django.shortcuts import render >> from django.http import HttpResponse >> >> def homepage(request): >> return HttpResponse("<h1>You are looking music!!") >> >> def detail(request, album_id): >> return HttpResponse("<h2>Details for Album id:"+ str(album_id)+ "</h2>") >> >> >> urls.py >> >> from django.urls import path >> from . import views >> >> app_name="music" >> >> urlpatterns=[ >> #/music/ >> path('',views.homepage,name='homepage'), >> >> # /music/712 >> path('<album_id>[0-9]+/',views.detail,name='detail'), >> ] > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > 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/848dc27b-9d4c-42a1-a691-c74ac4112e41%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 [email protected]. To post to this group, send email to [email protected]. 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/01D40376-A294-48D1-AD09-47C6A3E25C6B%40gmail.com. For more options, visit https://groups.google.com/d/optout.

