Comments (17)
This is because you do not have any way to access download/6.jpg
according to your urls.py - as the 404 error suggests.
Without seeing more of what you've done already it's hard to know what
you've done wrong.
You will not want to add protected/download to urls.py - as that would
defeat the purpose of the app and make the file publicly accessible.
On 13/08/12 23:34, rentgeeen wrote:
Hello,
I want to apologize first if this will be simple problem, learning
django and was trying your app. Was able to work out all of it except
the last part.I can load image or file to Django Admin and the url of the image is:
download/6.jpgwhen I click it will get an error:
http://cl.ly/image/0P420L0f3l1M
Even if I click in download list when files are public same error,
probably I need to add that URL "protected/download" to urls.py but I
would need to create a view then no?Can you tell me the proper way to setup your example?
Thanks
—
Reply to this email directly or view it on GitHub
#7.
from django-sendfile.
Hello would you help me if I give you ftp, its basically all what is in example folder and it created protected folder within the app and I was also able to use admin and created records but when I click on them or in download list that error I got. I can give u ftp to your email I am trying to solve this for a long time, let me know thanks a lot
from django-sendfile.
Is it possible?
from django-sendfile.
Hi,
I'm not really keen on ftp'ing into your server to fix things.
The links in the admin will mostly likely not work unless you want to
handle them differently. Django send file doesn't fix this for you.
You'd need to add a new url and view something like:
views.py:
def admin_download_file(request, filename):
if request.user.is_admin:
path = 'download/%s' % filename
return sendfile(request, filename)
# send forbidden response
urls.py:
url('download/(?P.+)$', admin_download_file)
That way you'd only allow admin users to get direct access to the files
via their filename.
cheers,
John
On 15/08/12 18:10, rentgeeen wrote:
Is it possible?
—
Reply to this email directly or view it on GitHub
#7 (comment).
from django-sendfile.
I am only trying to make your app work. I thought by this, you allowing logged users to download the files.
@login_required
def _auth_download(request, download):
if not download.is_user_allowed(request.user):
return HttpResponseForbidden('Sorry, you cannot access this file')
return sendfile(request, download.file.path)
I need to also define this?
def admin_download_file(request, filename):
if request.user.is_admin:
path = 'download/%s' % filename
return sendfile(request, filename)
# send forbidden response
from django-sendfile.
The 2nd function is only need if you want the links in the admin to work
(the ones next to the file browse buttons - that the admin auto-generates).
If you don't care about those then they aren't needed.
The 2nd function (admin_download_file) was merely my quick suggestion to
make those links work as you'd expect. It was untested, so probably
won't work as is.
On 16/08/12 16:12, rentgeeen wrote:
I am only trying to make your app work. I thought by this, you allowing
logged users to download the files.@login_required
def _auth_download(request, download):
if not download.is_user_allowed(request.user):
return HttpResponseForbidden('Sorry, you cannot access this file')
return sendfile(request, download.file.path)I need to also define this?
def admin_download_file(request, filename):
if request.user.is_admin:
path = 'download/%s' % filename
return sendfile(request, filename)send forbidden response
—
Reply to this email directly or view it on GitHub
#7 (comment).
from django-sendfile.
models.py
from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
from django.core.files.storage import FileSystemStorage
sendfile_storage = FileSystemStorage(location=settings.SENDFILE_ROOT)
class Download(models.Model):
users = models.ManyToManyField(User, blank=True)
is_public = models.BooleanField(default=True)
title = models.CharField(max_length=255)
# files stored in SENDFILE_ROOT directory (which should be protected)
file = models.FileField(upload_to='download', storage=sendfile_storage)
def is_user_allowed(self, user):
return self.users.filter(pk=user.pk).exists()
def __unicode__(self):
return self.title
@models.permalink
def get_absolute_url(self):
return ('download', [self.pk], {})
urls.py
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^', include('myproject.download.urls')),
(r'^accounts/login/$', 'django.contrib.auth.views.login'),
(r'^admin/', include(admin.site.urls)),
)
urls.py
from django.conf.urls.defaults import *
from .views import download, download_list
urlpatterns = patterns('',
(r'^$', download_list),
(r'(?P<download_id>\d+)/$', download, name='download'),
)
views.py
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponseForbidden
from django.db.models import Q
from django.template import RequestContext
from sendfile import sendfile
from .models import Download
def download(request, download_id):
download = get_object_or_404(Download, pk=download_id)
if download.is_public:
return sendfile(request, download.file.path)
return _auth_download(request, download)
@login_required
def _auth_download(request, download):
if not download.is_user_allowed(request.user):
return HttpResponseForbidden('Sorry, you cannot access this file')
return sendfile(request, download.file.path)
def download_list(request):
downloads = Download.objects.all()
if request.user.is_authenticated():
downloads = downloads.filter(Q(is_public=True) | Q(users=request.user))
else:
downloads = downloads.filter(is_public=True)
return render_to_response('download/download_list.html',
{'download_list': downloads},
context_instance=RequestContext(request))
setting.py (bottom)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'myproject.download',
)
SENDFILE settings
#SENDFILE_BACKEND = 'sendfile.backends.development'
#SENDFILE_BACKEND = 'sendfile.backends.xsendfile'
SENDFILE_BACKEND = 'sendfile.backends.nginx'
SENDFILE_ROOT = os.path.join(PROJECT_ROOT, 'protected')
SENDFILE_URL = '/protected'
from django-sendfile.
Oh ok, dont care about them, I want the to work, when I log in I got that error and no file is downloaded. When I am not logged in I can see the template and publick links also when I am logged in I can see the template but when I click the links it makes that url error.
from django-sendfile.
So which link are you clicking? What is the URL of the link?
The code you've sent just looks like my example code. I can see though
that you've set:
SENDFILE_BACKEND = 'sendfile.backends.nginx'
Have you configured nginx to serve the files up properly for you?
What happens if you use:
SENDFILE_BACKEND = 'sendfile.backends.development'
instead? (Just for testing)
On 16/08/12 16:34, rentgeeen wrote:
Oh ok, dont care about them, I want the to work, when I log in I got
that error and no file is downloaded. When I am not logged in I can see
the template and publick links also when I am logged in I can see the
template but when I click the links it makes that url error.—
Reply to this email directly or view it on GitHub
#7 (comment).
from django-sendfile.
I am clicking the link in the template "download list" like test1 and when I log in I can see test 2 both throwing that error.
Installed sendfile with python2.7 setup.py install command, how cam check if I setup nginx to serve files properly? should I remove that line? thanks
from django-sendfile.
Ah - yes!
Comment out:
SENDFILE_BACKEND = 'sendfile.backends.nginx'
and uncomment:
SENDFILE_BACKEND = 'sendfile.backends.development'
I hadn't realised the example had nginx set on by default - I'll correct
that now.
On 16/08/12 16:53, rentgeeen wrote:
I am clicking the link in the template "download list" like test1 and
when I log in I can see test 2 both throwing that error.Installed sendfile with python2.7 setup.py install command, how cam
check if I setup nginx to serve files properly? should I remove that
line? thanks—
Reply to this email directly or view it on GitHub
#7 (comment).
from django-sendfile.
I am in subway now on iphone cant get to terminal now will let you know asap if that worked thanks
from django-sendfile.
SENDFILE settings
SENDFILE_BACKEND = 'sendfile.backends.development'
#SENDFILE_BACKEND = 'sendfile.backends.xsendfile'
#SENDFILE_BACKEND = 'sendfile.backends.nginx'
SENDFILE_ROOT = os.path.join(PROJECT_ROOT, 'protected')
SENDFILE_URL = '/protected'
Just switched it and it started working like a charm, that was the problem :) great app thanks a lot...
1 more question, what does this do: #SENDFILE_BACKEND = 'sendfile.backends.xsendfile' ?
thanks a lot
from django-sendfile.
1 more thing in the Admin how can I edit the Downloads that I created, cause when I click ADD I can fill that form but when its done and want to edit it, it will show me only the file that I uploaded not the form...why is that?
from django-sendfile.
Nevermind fixed it by putting Admin on the top:
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'^', include('myproject.download.urls')),
(r'^accounts/login/$', 'django.contrib.auth.views.login'),
)
thanks a lot great plugin :)
from django-sendfile.
sendfile.backends.xsendfile is so you can use mod_sendfile for apache
https://tn123.org/mod_xsendfile/ or sendfile in lighthttpd to
efficiently send files to users (rather than Django doing it).
On 17/08/12 01:26, rentgeeen wrote:
Nevermind fixed it by putting Admin on the top:
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'^', include('myproject.download.urls')),
(r'^accounts/login/$', 'django.contrib.auth.views.login'),
)thanks a lot great plugin :)
—
Reply to this email directly or view it on GitHub
#7 (comment).
from django-sendfile.
my next step is to make it like upload to s3 (large files not boto) and protect it somehow...curious how would that work
from django-sendfile.
Related Issues (20)
- mod_wsgi backend broken on Django 1.8 HOT 9
- Our abc.tar.gz file sent using this django-sendfile was automatically getting unzipped by the browser
- Release 0.3.8 HOT 2
- Licensing HOT 4
- Problem with unicode characters HOT 10
- PyPi page looks strange HOT 2
- Is status really "Beta"? HOT 5
- Content-Disposition: Output contains buffer repr (Python 3.4) HOT 1
- Django 1.9 support HOT 4
- How to make "private" media accessible by site staff? HOT 1
- Add tests running in CI
- Support wheel packaging
- Serve a folder with sendfile
- Simple backend will decompress file HOT 1
- Maintaining the project HOT 12
- Apache 2.4 EnableSendfile as a potential replacement for XSendfile HOT 3
- I have to append `media/` to the path to not get a 404
- How to override the image url / path?
- Django 2.1 and above has removed the permalink() decorator HOT 1
- Please redirect to django-sendfile2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-sendfile.