1

I need to serve a particular static asset only to users logged into my Django site. I'm serving static assets through Apache. For various reasons I’m not interested in standing up a full CMS — I just need to make sure non-qualified site visitors cannot download this particular file.

This is really low traffic site so failing all else I can hardcode a urlpattern & serve it as a template.

But there's gotta be a smarter way to do this, right?

EDIT:

Here’s where I settled for now:

# views.py
from django.shortcuts import render
from django.contrib.auth.decorators import login_required

@login_required
def secretfile(request):
    return render(request, 'secretfile.xls')


# urls.py
from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'secretfile.xls', views.secretfile),
]
axoplasm
  • 502
  • 2
  • 10
  • Wow literally no one answered this in 2 years. Maybe this could help you if you use Nginx: https://wellfire.co/learn/nginx-django-x-accel-redirects/. (If you already found a solution, please tell me so! :D) – Myzel394 May 07 '20 at 17:45
  • Checkout [this answer](https://stackoverflow.com/a/5809920/10293585), seem to me that this is a similar issue – Zhigal Oct 25 '21 at 20:51

0 Answers0