How to receive uploaded file from the inlined form in django?
request.FILES should work fine with that handmade form. Django doesn't do anything different with the field except adding the id="id_file". I'm fairly certain that your not having an id wouldn't interfere with the transference into request.FILES.
In [5]: from django import formsIn [6]: class GenericFileForm(forms.Form): ...: file = forms.FileField() ...: In [7]: g = GenericFileForm()In [8]: print g<tr><th><label for="id_file">File:</label></th><td><input type="file" name="file" id="id_file" /></td></tr>
I suggest using a template fragment which generates the form , but which also can be generated seperately and sent to the jquery. this preservers CSRF tokens and allows tou to parse the file with forms correctly
for instance you would use:
$.ajax({ url: "/uploadPicture?JustForm", dataType: ($.browser.msie) ? "text" : "html", success: function(data){ // Put the form contained in data onto the page (it's a string) $("formContainer").innerHtml(data) }});
then have your form as returned directly by your view
def upload_picture(request): if request.GET.has_key('JustForm'): return YourFormObject.as_html() <- will include CSRF tags for compat with 1.2 if request.method == 'POST': save_original(request.FILES['file']) return HttpResponseRedirect('admin/edit_inline/picture_editor.html')
(disregard blatent errors, treat like pseudocode)