1

I got a site, say it's "www.site.com". I need to serve a text file at the root, so that "www.site.com/text.txt" will show up.

I read through this answer: Django download a file, and I used the "download" function.

However I am at a loss how to configure the URL. Can someone help me out?

Say I put this this into my url.py,

url('^(?P<path>.*)/$', san.views.FileDownload.as_view()),

This then supersedes all my other url patterns and render them useless. How do I make this work? Thanks!

Community
  • 1
  • 1
reedvoid
  • 1,203
  • 3
  • 18
  • 34

1 Answers1

2

Put it as the last urlpattern in your urls.py to ensure it doesn't sccop up everything. It should not have the trailing / either, i.e.

url('^(?P<path>.*)/?$', san.views.FileDownload.as_view()),

This will match the request "/YOUR_FILE.txt", and is also case-insensitive.

url(r'^(?i)YOUR_FILE.txt$', san.views.FileDownload.as_view()),
Matt
  • 8,758
  • 4
  • 35
  • 64