Thursday, November 29, 2012

Re: Where to put PDF files + how to authenticate the urls requesting them

I am still new to sreving stuff (in fact I know barely anything about it :)) Then you instruct to have something like this

        url(r'^media/(?P<path>.*)$', 'myview,func', {
            'document_root': MEDIA_ROOT,
        }),

and my func have the instructions to the real web servers ?

And another question: Does this applies also to light static files like css and javascript ?

Thanks a lot

On Thu, Nov 29, 2012 at 1:15 PM, Tom Evans <tevans.uk@googlemail.com> wrote:
On Wed, Nov 28, 2012 at 6:27 PM, Loai Ghoraba <loai1991@gmail.com> wrote:
> Thanks for the reply, but I am still new to the web technology world, so I
> would like to fully use Django now before , moving to another ways to host
> my files.
> Actually I am totally new to serving stuff, so if there is some best
> practice or that my way is totally wrong, please tell me.
>
> So in short: is there a way to provide some kind of authentication against
> /static/whatever urls ? Because I want Django to host the file now
> Also,  assuming I found someway to do this, django says that to mark a file
> as downloadable, we can do this
>
> https://docs.djangoproject.com/en/dev/ref/request-response/#telling-the-browser-to-treat-the-response-as-a-file-attachment
>
>>>> response = HttpResponse(my_data,
>>>> content_type='application/vnd.ms-excel')
>>>> response['Content-Disposition'] = 'attachment; filename="foo.xls"'
>
>
> Now what is the type of my_data? any file object ?
>

A string, or any file like object - it's just like any HttpResponse.

You do not want to do this though, using Django to download static
files is very wasteful. Others have pointed out solutions where you
use django to authenticate the request, and then instruct your web
server (eg Apache, nginx) to serve the correct file, which will be an
order of magnitude more efficient.

Django is never served by itself, there should always be a real web
server in front of it.

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment