The easiest thing, which you may or may not find to be adequate, is to use an "if" tag in the template to do one of: Not render the button if you are not logged in, or Render a button that has the correct link if you are logged in but links to a "you must log in" page if you are not, or Render the correct button if you are logged in, but render a dummy disabled button if you are not
I must point out that security is limited, since a logged in user could capture the link to share with anyone, but he could also simply share the file after download, so there can only be security if you can trust ALL of your logged in users. Django's template system, and what you must do to have access to the user object in the template, and how to test whether it is anonymous or authenticated are well covered in the documentation and/or discussed in the mailing list archives. Bill On Wed, Jun 5, 2013 at 6:44 AM, A T.Khan <atkhan...@gmail.com> wrote: > Hello everyone, > > I am relatively new on Django, in fact I got to know about it through > Openstack Dashboard which works using Django. anyway I got a question and I > been looking for it for a month now without getting any good results, I > finally decided to ask some of the experts here. If I am violating any > rules by posting it or if someone has already answered it, please tell me. > I hope this community is friendly enough to oversee this. > > I have already a Django setup running (you guessed it devstack), and it > works fine. I have done plenty of editing already. But now I want to add a > download button on a page, and by clicking to it, a file should be > downloaded. Seems simple enough, but right now what I have done is adding > > <a href="{{ MEDIA_URL }}/test.file" %}" class="btn-download">{% trans > "Downloadl" %}</a> > > in one of the files. This works perfectly ... however this link works but > It is simple html encoding, and it works even when I am not logged in, > bypassing the entire purpose of file security. I have tried to embed the > code in some py files but then it gives me debug error. > > So I will be really grateful if someone can guide me what to do here. All > I want is to add a download button/link on a page and a file to be > downloaded. I tried staticfiles and media_url methods, not the result I > want. Please help me that where I need to make changes in which > configuration files and how will it work. > > Thanks in Advance > > Best of Regards, > AT > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.