Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 8, 2010 02:55:33

dmitry b.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

handling generated files


Hi,

How do I use Django's FileField with autogenerated files? That is,
these files aren't uploaded by a user, but rather are created on the
fly. I've looked at ContentFile, but this class doesn't seem to have
a way to attach a file name (the name is also computed at run-time
based on some criteria). Do I need to write my own implementation of
File for this or am I missing an existing class?


Thanks
Dmitry

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 8, 2010 19:02:11

Mark (.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

handling generated files


On Dec 7, 7:55 pm, dmitry b <dmitry.ma...@gmail.com> wrote:
> Hi,
>
> How do I use Django's FileField with autogenerated files?  That is,
> these files aren't uploaded by a user, but rather are created on the
> fly.  I've looked at ContentFile, but this class doesn't seem to have
> a way to attach a file name (the name is also computed at run-time
> based on some criteria).  Do I need to write my own implementation of
> File for this or am I missing an existing class?
>
> Thanks
> Dmitry

Hello,

I'm not sure I understand the question so am making the following
assumptions. Sorry if this isn't what you are looking for.

1. You know how to access the generated content.
2. You want to serve the content as a file with a specific name.

For this example let's say your file is a CSV file with content in
FILE_CONTENT. You will need to set a few thing up in you http
response to serve up a proper csv file.

response = HttpResponse(mimetype='text/csv')
response = 'attachment; filename=%s' %
'MyRandomFileName'
response.write(FILE_CONTENT)
return response

You can set other header options like Expires, Content-Length, etc. in
this fashion.

Hope I helped.
Mark

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 12th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support