django download csv file using a link

前端 未结 3 1232
旧巷少年郎
旧巷少年郎 2020-12-28 09:41

I am a new to django and python. Need some guidance in this quest.

Case: When the user hits the submit button on a form, it should display Success page and a link wh

3条回答
  •  生来不讨喜
    2020-12-28 10:38

    In your urls.py change

    urls.py url(r'^static/(?P.*)$', send_file)
    

    to

    urls.py url(r'^static/example.xls$', send_file)
    

    In the first one, you are also passing everything after the / to the view as another parameter, but your view does not accept this parameter. another option would be to accept this parameter in the view:

    def send_file(request, path):
        ...
    

    but since the path to your xls file is hard coded, I don't think you need that.

提交回复
热议问题