Open In App

Music Player using Django

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we'll build a Music Player using Django. To get started, the first thing we'll do is create an account, just like with other music players. After creating the account, we'll log in. Once successfully logged in, we'll be redirected to the home page. On the home page, we can search for songs based on our preferences we used an API to fetch songs. Additionally, we'll have the option to add songs, and the corresponding pictures related to those songs will be displayed on the home page. We can easily play the songs and manage the login system through the admin panel.

Music Player using Django

Below is the step-by-step guide to playing music player

To install Django follow these steps.

Starting the Project Folder

To start the project use this command

django-admin startproject music_player_project
cd music_player_project

we create two apps for creating the app use this command

python manage.py startapp api
python manage.py startapp music_player_app

Now add this app to the ‘settings.py’

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"music_player_app",
"api",
"rest_framework"
]

Now add these two line in your 'settings.py'

LOGIN_REDIRECT_URL = '/home/'  # Redirect to home page after login
LOGIN_URL = '/login/' # Ensure this matches the URL of your login page

and also update this

import os
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

File Structure

project-structure
File Structure

Developing a music player using Django is a challenging project. For mastering Django's complex features and building robust applications, the Django Web Development Course can help you achieve that.

Setting Necessary Files

api/models.py :Below,code defines a Django model named "Song" with fields for id, title, category, artist, audio file, and audio image, along with their respective properties, and a string representation method returning the song title.

Python
# api/models.py
from django.db import models