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 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/CAMT%3DisUwfvM8grFurgdK44uyHm2%3Djaw8pihEu1YMzrfQboCz1w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to