0

I'm building a very simple website where a user authenticates and accesses a personal page from where they can download their paychecks. I've already implemented the login view, that redirects the user to the profile page. Now in the profile page, I need to add a list of paychecks to download. In order to do that, I need to take them from a static sub-directory with the same name as the user:

static/paychecks/username

I've been reading about serving static files, but I can't figure out how to do this specifically. Any help will be much appreciated.

Ariel
  • 1
  • So, if someone changes the URL to another username he's going get someone else's money? – Klaus D. Jan 30 '21 at 14:19
  • you can easily do that with url like `/paychecks//` and create view method which will render that html page. pass `context` as a `username` and in your html you can fetch static file path to display it. – Akash senta Jan 30 '21 at 14:47
  • **Update:** I realize the original question might not have been clear. The URL is going to be always mysite/profile, what changes is the content shown, depending on who's logged in. The username route is the route to the files to be served, not the URL, and those files should only be accessible to the corresponding user. – Ariel Jan 30 '21 at 14:55
  • @Ariel this might help you [Serve protected media files with django](https://stackoverflow.com/questions/39744587/serve-protected-media-files-with-django) also some libraries [django-protected-media](https://pypi.org/project/django-protected-media/), [django-private-storage](https://github.com/edoburu/django-private-storage) – Abdul Aziz Barkat Jan 30 '21 at 16:18

0 Answers0