![](/img/trans.png)
[英]Uploading a audio file to s3 with django-audiofield, django-storages, boto. django-storages This backend doesn't support absolute paths error
[英]django-audiofield no such file or directory when uploading new audio file from admin interface
我正在嘗試成功實現django-audiofield插件,但這是一個主要問題。 我可以正常工作,因為在管理界面中可以使用音頻字段識別我的新模型,但是當我嘗試使用新的音頻文件上傳它時,它會拋出錯誤並報錯我無法調試。
這是錯誤頁面日志。
Environment:
Request Method: POST
Request URL: http://45.63.1.97/admin/website/musicpost/add/
Django Version: 1.8.4
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_cleanup',
'pagedown',
'website',
'audiofield')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'audiofield.middleware.threadlocals.ThreadLocals')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in wrapper
616. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
110. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
233. return view(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in add_view
1516. return self.changeform_view(request, None, form_url, extra_context)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapper
34. return bound_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
110. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in bound_func
30. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in inner
145. return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in changeform_view
1467. self.save_model(request, new_object, form, not add)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in save_model
1078. obj.save()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in save
734. force_update=force_update, update_fields=update_fields)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in save_base
771. update_fields=update_fields, raw=raw, using=using)
File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py" in send
201. response = receiver(signal=self, sender=sender, **named)
File "/usr/local/lib/python2.7/dist-packages/django_audiofield-0.8.1-py2.7.egg/audiofield/fields.py" in _rename_audio
222. self._convert_audio(dst_fullpath, instance, ext[1:4])
File "/usr/local/lib/python2.7/dist-packages/django_audiofield-0.8.1-py2.7.egg/audiofield/fields.py" in _convert_audio
140. response = subprocess.Popen(command.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py" in __init__
710. errread, errwrite)
File "/usr/lib/python2.7/subprocess.py" in _execute_child
1327. raise child_exception
Exception Type: OSError at /admin/website/musicpost/add/
Exception Value: [Errno 2] No such file or directory
這是我的模型的代碼。
# Music post model
class MusicPost (models.Model):
# Creation time field
created_at = models.DateTimeField(auto_now_add=True)
# Updated time field
updated_at = models.DateTimeField(auto_now=True)
# Body text for the post
body = models.TextField()
# Add the audio field to your model
audio_file = AudioField(upload_to='/root/goodbyejuly/media', blank=True,
ext_whitelist=(".mp3", ".wav", ".ogg"),
help_text=("Allowed type - .mp3, .wav, .ogg"))
# Add this method to your model
def audio_file_player(self):
"""audio player tag for admin"""
if self.audio_file:
file_url = settings.MEDIA_ROOT + str(self.audio_file)
player_string = '<ul class="playlist"><li style="width:250px;">\
<a href="%s">%s</a></li></ul>' % (file_url, os.path.basename(self.audio_file.name))
return player_string
# Audio field settings
audio_file_player.allow_tags = True
audio_file_player.short_description = ('Audio file player')
這就是我在管理界面中注冊模型的方式。
admin.site.register(MusicPost, MarkdownModelAdmin)
這是我用於正文文本的markdown模型管理小部件,過去對我來說效果很好。
# Admin interface override for text field markdown preview
class MarkdownModelAdmin (admin.ModelAdmin):
# Override specific model fields
formfield_overrides = {
# Override text fields to show markdown previews
models.TextField: {'widget': AdminPagedownWidget },
}
誰能幫我解決我的問題? 如果您需要更多信息,我會提供。
如Alex所述,一種解決方案是安裝soxi 。 您可以使用以下命令進行操作( 我的發行版是ubuntu 14 )。
完整指南的鏈接是http://linuxg.net/how-to-install-sox-14-4-1-on-ubuntu-14-10-ubuntu-14-04-and-derivative-systems/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.