0

I'm trying to generate music with lilypond and render it to django template. When I try to run the script in cmd, midi file is generated but I can't render it to django template.

this works fine in cmd and generates music file which can be played -and rest of the code- :

views.py

 -> lyout = subprocess.Popen(["lilypond", song_name])
 out, err = lyout.communicate()
 return render(request, "smcs/result.html", out)

this is my html template:

result.html page

{% for song in out %}
<audio controls preload="auto" id="audio" autoplay="autoplay">
    <source src="../../{{ song }}" >
</audio>
{% endfor %}
  • In result page i only see the file name but player is not shown. When i delete the {% for - end%} commands player is shown but song is not playing.

urls.py

urlpatterns = [......] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

settings.py

MEDIA_ROOT=os.path.join(BASE_DIR,"songdir")
MEDIA_URL='/media/'
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.template.context_processors.media",
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

songs - urls.py

urlpatterns = [

url(r'^$', page),
url(r'^result/$', lygen) ]

lygen is my func name defined in views.py.

What am I doing wrong?? :(

vschultzx
  • 1
  • 2
  • could you open the songs url to see if the address is correct ? – iliya Jun 10 '20 at 16:38
  • @iliya hi ! "http://localhost:8000/music/result/" is the link. it isn't rendering correctly. – vschultzx Jun 10 '20 at 18:41
  • add your ```views``` as well. The problem lies there since you are getting ```{{ song }}``` from your ```view```. – iliya Jun 10 '20 at 18:50
  • @iliya i have two scripts for this one for control -running in cmd , one for this - running in django. the only different part between them is the lines i wrote up there :( "cmd" one is running perfectly but django one is not.. – vschultzx Jun 10 '20 at 19:50

0 Answers0