ずにジャンゴにファイルパスを返す、私はジャンゴ/ Pythonのに新たなんだ、これは非常によく私の問題に対する簡単な解決策があるかもしれません...私と一緒に裸してくださいファイル拡張子
私が作成していますユーザーが写真、ビデオ、オーディオをアップロードできるようにする私のDjangoサイト上のマルチメディアアプリケーション。ファイルはサードパーティのサービス(mp4、ogg、webm、flv、ビデオ用)でエンコードされ、Amazon S3上のユーザーのバケットに保存されます。私は特にユーザーの動画をHTML5形式で表示するための洗練されたソリューションを探しています。ここでは私のモデルがどのように見えるかです:
class Video(models.Model):
file = models.FileField(upload_to = user_video_folder)
owner = models.ForeignKey(User)
video_title = models.CharField(max_length=100)
video_caption = models.CharField(max_length=150, blank=True)
date_added = models.DateTimeField(auto_now_add=True)
date_updated = models.DateTimeField(auto_now=True)
def __unicode__(self):
return self.video_title
[表示:テンプレートで
def ViewAllVideos(request):
videos = Video.objects.filter(owner = request.user)
template = 'site/media-videos.html'
return render_to_response(template, {'videos': videos}, context_instance=RequestContext(request))
、私は、符号化時に生成された複数のファイル形式のパスを印刷する必要はなく、に期待していました私のモデルでの各列を形式に追加しなければならないので、ファイル名でファイルパスを返す方法があったのだろうと思っていましたが、拡張子がないのでテンプレートのようにします:
<video width="900" height="506" preload="" controls="" autoplay="">
<source src="{{ STATIC_URL }}{{ video.file }}.mp4" type="video/mp4;">
<source src="{{ STATIC_URL }}{{ video.file }}.ogg" type="video/ogg;">
<source src="{{ STATIC_URL }}{{ video.file }}.webm" type="video/webm;">
<object width="900" height="506" type="application/x-shockwave-flash" data="/foo/bar/flowplayer/flowplayer-3.2.5.swf">
<param name="movie" value="/foo/bar/flowplayer/flowplayer-3.2.5.swf"><param name="allowfullscreen" value="true">
<param value="config={"clip": {"url": "{{ STATIC_URL }}{{ video.file }}.flv", "autoPlay":false, "autoBuffering":true}}" name="flashvars">
</object>
</video>
お手数ですがご了承ください!乾杯!
ここに私の新しいビューです:
def ViewAllVideos(request):
videos = Video.objects.filter(owner = request.user)
filenames = [os.path.splitext(os.path.basename(video.file))[0]
for video in videos]
context = {
'videos': videos,
'filenames': filenames,}
template = 'site/media-videos.html'
return render_to_response(template, context, context_instance=RequestContext(request))
これはすばらしいです、ありがとう!私がこれを持っている唯一の問題は、画像への完全なパスを返すことですが、別個の静的URLを指定する必要があります。ファイル名のみを返すことは可能ですか?したがって、たとえば: static.myurl.com/username/videos/foo.mp4 戻り値: foo –