how to pass file from local storage to html using django

So i was using form to input file from html to local storage using django (im NOT using database / modals). Now i want get my file again and shown to my html. the file is song (mp3), so i want, the song what i uploaded to local storage can be played in web html.

but i don’t know how to pass it. please explain and help me. thank you

You want to use a model in your application to keep track of the file. It’s going to make everything easier that way.

i want but i don’t use database. it’s make me must use form, because i just want to keep my file to local storage. or can i use models without use database? or maybe can i use formset to get file from local?

If you are using Django, you will have a database. Django requires one for its operation.

When using a FileField, the files don’t get stored in the database - they get stored in the file system. The FileField tracks the location of the files, giving you an easy means of accessing those files later.

ah i see. i was using FileField. How to get the data then? Here’s my code :slight_smile:

class Audio_store(forms.Form):

    password=forms.FileField(widget=forms.FileInput(attrs={'style': 'width: 300px;', 'class': 'form-control',

    'text-align' : 'center;'}))

    audio=forms.FileField(widget=forms.FileInput(attrs={'style': 'width: 300px;', 'class': 'form-control',

    'text-align' : 'center;'}))

See the docs at:

could you give me references not using models? because i don’t use models and database

You want to use a model in your application to keep track of the file. It’s going to make everything easier that way.

i know, but my project not gonna use model. because, i don’t use and make database. so i’m using form.

It’s not an either / or situation. You use a form to get input from the browser. You save that data in the models. You use the models to save the data in the database. Forms don’t save data.
In other words, the two features work together. (Forms and models)

So i can use model without must make database and use it? how to save data to models from form without database then?

No. You will have a database, you can’t run Django at all without one.

but i can start my program now and i don’t use database or make it

Please post the contents of your settings.py file.

here’s all my settings.py file, sorry late to reply

"""

Django settings for MusicLockApp project.

Generated by 'django-admin startproject' using Django 3.0.14.

For more information on this file, see

https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see

https://docs.djangoproject.com/en/3.0/ref/settings/

"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production

# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!

SECRET_KEY = 'rkle8apj*z6j%&(@&-za$9e5o-0m1^#hr5&lk0@f-_=koz25i&'

# SECURITY WARNING: don't run with debug turned on in production!

DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [

    'MusicLockApp',

    'django.contrib.admin',

    'django.contrib.auth',

    'django.contrib.contenttypes',

    'django.contrib.sessions',

    'django.contrib.messages',

    'django.contrib.staticfiles',

    'crispy_forms',

]

CRISPY_TEMPLATE_PACK = 'uni_form'

MIDDLEWARE = [

    'django.middleware.security.SecurityMiddleware',

    'django.contrib.sessions.middleware.SessionMiddleware',

    'django.middleware.common.CommonMiddleware',

    'django.middleware.csrf.CsrfViewMiddleware',

    'django.contrib.auth.middleware.AuthenticationMiddleware',

    'django.contrib.messages.middleware.MessageMiddleware',

    'django.middleware.clickjacking.XFrameOptionsMiddleware',

]

CSRF_COOKIE_SECURE = True

ROOT_URLCONF = 'MusicLockApp.urls'

TEMPLATES = [

    {

        'BACKEND': 'django.template.backends.django.DjangoTemplates',

        'DIRS': ['templates', 'assets'],

        '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',

            ],

        },

    },

]

WSGI_APPLICATION = 'MusicLockApp.wsgi.application'

# Database

# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.sqlite3',

        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),

    }

}

# Password validation

# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [

    {

        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',

    },

    {

        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',

    },

    {

        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',

    },

    {

        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',

    },

]

# Internationalization

# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)

# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'

STATICFILES_DIRS = (

    os.path.join(BASE_DIR, 'assets'),

)

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

You are using a database.

It’s defined right here:

but i mean, i don’t make database for saving something

That’s a different issue, and will change for you to be able to do what you want to do.

what do you mean will change it? so i can use it to get my file from local?

I mean, if you want to build the application you want to build, you will start using that database.