2011-07-13 33 views
3

私は、認証されたユーザーに提供する必要があるイメージ、ビデオなどのような静的ファイルのセットを持っています(つまり、そのクッキーはセッションで認証されて登録されています) 。静的ファイルのdjango認証

これらのファイルを認証する必要が私の静的ファイルがかなり大きくなることを考えると、別やCSSなどの他のメディアの静的ファイルに関連決して、javaacriptなど

あり、私はどうなるかと思いましてそれらを提供する最も効率的な方法(btw、私はwsgiを使用しています)。私は現在、あなたが上記の使用しているものと同様の機能を使用してい

def return_large_file(request, p_filename): 
    """                   
    Send a file through Django without loading the whole file into    
    memory at once. The FileWrapper will turn the file object into an   
    iterator for chunks of 8KB.             
    """ 
    if not os.path.exists(p_filename): 
     raise Exception('File %s does not exist!') 

    try: 
     _content_type = mimetypes.guess_type(p_filename) 
    except: 
     _content_type = 'application/octet-stream' 

    wrapper = FileWrapper(file(p_filename)) 
    response = HttpResponse(wrapper, content_type=_content_type) 
    response['Content-Length'] = os.path.getsize(p_filename) 
    return response 

答えて

1

現在、私はこれを持っています。

パフォーマンス/効率が問題になると思っていましたが、Apache mod-auth-externalを使用して、指定されたファイルに対して私のカスタム認証を行います。

私の経験に基づいているのではなく、自分の研究が私を導いてくれたこの回答を提供しています。

関連する問題