Is this in production or development? What is the url that doesn't work? What happens when you try the url?
Regards,
A.
Antonis Christofides http://djangodeployment.com
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c505a804-3cc6-4584-a47a-bffadee6fb5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
return render(request, "export.html", {'out': urlOut})
Lien du <a href="{{out}}"> fichier </a>
You cannot get a file outside of your project unless you symlink it inside the project. This is also a Very Bad Thing(TM) as it may allow attackers to request arbitrary files.
What you should do instead is this:
1) Put Data/01/export.txt to the static/ folder inside your app (with the same folder structure if you need it that way)
2) Build the path to your file with /static/ as prefix, i.e. http://127.0.0.1/static/Data/01/export.txt
You cannot get a file outside of your project unless you symlink it inside the project. This is also a Very Bad Thing(TM) as it may allow attackers to request arbitrary files.
You can get a file outside your project. Whether this is a bad thing or not depends on why and how. I also don't think this file should be placed in the static directory. The static directory is for files that don't change after the program is installed. The media directory might be more appropriate.
If what you are doing is to dynamically create a csv file for your user to download immediately, one possible way of doing that is (untested):
from tempfile import TemporaryFile csvfile = TemporaryFile() export_your_data_to_the_file(csvfile) file_size = csvfile.tell() csvfile.seek(0) response = HttpResponse(csvfile.read(), content_type='text/csv') response['Content-Disposition'] = 'attachment; filename=whateveryoulike.csv' response['Content-Length'] = str(size) return response
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/j5ftp2xrd2aps3c4mtn66umn.1493736693783%40email.android.com.
You cannot get a file outside of your project unless you symlink it inside the project. This is also a Very Bad Thing(TM) as it may allow attackers to request arbitrary files.You can get a file outside your project. Whether this is a bad thing or not depends on why and how. I also don't think this file should be placed in the static directory. The static directory is for files that don't change after the program is installed. The media directory might be more appropriate.
If what you are doing is to dynamically create a csv file for your user to download immediately, one possible way of doing that is (untested):
from tempfile import TemporaryFile csvfile = TemporaryFile() export_your_data_to_the_file(csvfile) file_size = csvfile.tell() csvfile.seek(0) response = HttpResponse(csvfile.read(), content_type='text/csv') response['Content-Disposition'] = 'attachment; filename=whateveryoulike.csv' response['Content-Length'] = str(size) return responseRegards,
A.
Antonis Christofides http://djangodeployment.comOn 2017-05-02 17:53, m712 - Developer wrote:
You cannot get a file outside of your project unless you symlink it inside the project. This is also a Very Bad Thing(TM) as it may allow attackers to request arbitrary files.
What you should do instead is this:
1) Put Data/01/export.txt to the static/ folder inside your app (with the same folder structure if you need it that way)
2) Build the path to your file with /static/ as prefix, i.e. http://127.0.0.1/static/Data/01/export.txt
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20170503133519.05365d67%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.
You might want to check out WhiteNoise (https://whitenoise.readthedocs.io/en/stable/) perhaps in conjunction with a CDN
On 3 May 2017 at 19:35, Tim Chase <django...@tim.thechases.com> wrote:
On 2017-05-02 19:11, Antonis Christofides wrote:
> response = HttpResponse(csvfile.read(), content_type='text/csv')
Beware that, if your content can get huge (some of our reports can
run to hundreds of megabytes), you might want to investigate
something like the "sendfile" alternatives or spew it out as generator
instead of doing .read() to suck the whole thing into memory.
-tkc
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20170503133519.05365d67%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.