Closed oliverbienert closed 4 years ago
I solved my problem for now by not using middleware but the decorator only. As I have only one downloadview, this is even less configuration. Nevertheless I'd like to know if the above error would be solved by applying #142 and #144. Maybe I'll find the time to test it in the next couple of days. Until then, I'm happy with the decorator. Here is my code and a py.test: urls.py:
urlpatterns = [
url(r'^map-file/(?P<pk>[a-zA-Z0-9_-]+)/$',
django_views.map_file_view,
name='map_file'),
]
The view:
from django.http import Http404
from django_downloadview import ObjectDownloadView
from django_downloadview.nginx import x_accel_redirect
from api.models import Map
class MapDownloadView(ObjectDownloadView):
def get(self, request, *args, **kwargs):
"""Handle GET requests: stream a file."""
self.object = self.get_object()
try:
return self.render_to_response()
except AttributeError as e:
print(e)
raise Http404("An attribute error occurred.")
map_file_view = x_accel_redirect(
MapDownloadView.as_view(model=Map),
source_url='/media/',
destination_url='/media/')
The test file:
import pytest
from django.core.urlresolvers import reverse
from django_downloadview.nginx.response import XAccelRedirectResponse
from django.test import Client
pytestmark = pytest.mark.django_db
client = Client()
@pytest.fixture
def prepare(map_factory):
# Create a file object using factory boy
map_factory()
@pytest.mark.usefixtures("prepare")
def test_response():
"""
Returns X-Accel response.
"""
url = reverse('map_file', kwargs={'pk': 0})
response = client.get(url)
assert isinstance(response, XAccelRedirectResponse)
conftest.py in the api/tests:
from pytest_factoryboy import register
from config.tests.factories import MapFactory
register(MapFactory)
factories.py in config/tests:
import factory
from api.models import Map
class MapFactory(factory.django.DjangoModelFactory):
class Meta:
model = Map
django_get_or_create = ('pk',)
pk = 0
file = factory.django.FileField(filename='example.dat')
Hello, I've used your package for a while now, with a simple ObjectDownloadView, which is working without problems. Now I want to optimize the download by using nginx acceleration, but when I change settings as described in docs and demo project, an error is raised, when I try to start the django server.
settings
view
url config app
url config global
error
What do I miss here? Python 2.7.14 Django Downloadview 1.9 Django 1.11.7
Is this perhaps related to #142?
Regards Oliver