如何在runserver --insecure中提供媒体文件?

时间:2015-01-21 08:58:21

标签: django

runserver --insecure

时,有没有办法提供媒体文件?

它只提供css和js和图像,但我需要用...提供媒体文件。

They提到cachefile不可能,但没有关于媒体的消息。

2 个答案:

答案 0 :(得分:3)

您需要告诉它为您的媒体文件提供服务。在urls.py

from django.conf import settings
if settings.DEBUG == False:
    urlpatterns += patterns('',
        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.MEDIA_ROOT,
        }),
        url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.STATIC_ROOT,
        }),
)

答案 1 :(得分:0)

写:

class MainActivity : AppCompatActivity() {

    private val player: SimpleExoPlayer by lazy { SimpleExoPlayer.Builder(applicationContext).build() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        player.preparePlayer(playerView, playerViewFullscreen)
        player.setSource(applicationContext, "http://html5videoformatconverter.com/data/images/happyfit2.mp4")
        player.playWhenReady = true
    }

    public override fun onPause() {
        super.onPause()
        player.playWhenReady = false
    }

    public override fun onDestroy() {
        player.release()
        super.onDestroy()
    }
}

然后在import re from urllib.parse import urlsplit from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.urls import re_path from django.views.static import serve def static(prefix, view=serve, **kwargs): return [ re_path(r'^%s(?P<path>.*)$' % re.escape(prefix.lstrip('/')), view, kwargs=kwargs), ] 中输入

urls.py