On Wed, Sep 6, 2017 at 6:03 AM, giuseppe ricci <peppepega...@gmail.com> wrote:
> Thank you James for your reply.. > So in my urls.py I insert a new entry: > > url(r'^download/$', 'views.download') > > and my view to download a file is: > > def download(request): > file_path = 'static/tmp/' #settings.MEDIA_ROOT > return render_to_response('download.html', file_path+'dati.csv') > > Your view should look similar to what the Django docs show here: https://docs.djangoproject.com/en/1.11/howto/outputting-csv/ Is this a file that is publicly available? If so, it may be more efficient to have the web server process handle the download directly rather than Django. That would require a working setup for your STATIC_DIR and MEDIA_DIR. If that's the case, simply add a link to the file URL directly, something like this in your template: <a href="{{ file_path }}">Download</a> Where {{ file_path }} is a path to the file in your media or static files (if the file changes, use the media directory, if it stays the same, use the static directory). Your web server should be configured to serve your MEDIA_URL and STATIC_URL already. This site appears to have several approaches detailed: http://voorloopnul.com/blog/serving-large-and-small-files-with-django/ -James -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciV9TO6q3W5EzAKGvhv7nTeeg_XTjmYXWS0QMMUzB5qoBw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.