Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to first upload the file and save it into disk (or memory), then you need to save the this state for the next request. You have a few methods of doing that, for example in the session.</p> <p>Here's an example, it's not tested and might have some errors...</p> <pre><code>FILE_UPLOAD_DIR = '/tmp' class UploadFileForm(forms.Form): file = forms.FileField() @login_required def uploadFunc(request, username): user = get_object_or_404(User, username=username) if request.method == 'GET': return render_to_response('upload.html',{'user':user},context_instance=RequestContext(request)) elif request.method == 'POST': form = UploadFileForm(request.POST, request.FILES) if form.is_valid(): path = _handle_uploaded_file(request.FILES['file']) request.session['uploaded_file'] = path return HttpResponseRedirect("/") def index(request): if request.session.get("uploaded_file", None): lines = [] with open(request.session.pop("uploaded_file"), 'rb') as f: reader = csv.reader(f) for m in reader: lines.append(m) return render_to_response('index.html', { 'file_lines': lines }, context_instance=RequestContext(request)) def _handle_uploaded_file(source): fd, filepath = tempfile.mkstemp(prefix=source.name, dir=FILE_UPLOAD_DIR) with open(filepath, 'wb') as dest: shutil.copyfileobj(source, dest) return filepath </code></pre> <p>Then in the template for <em>index.html</em> you can use the <em>file_lines</em> to populate the table.</p> <p>I "glued" this code from various snippets I found just now, here's the list of urls:</p> <ul> <li><a href="https://docs.djangoproject.com/en/dev/topics/http/file-uploads/" rel="nofollow noreferrer">https://docs.djangoproject.com/en/dev/topics/http/file-uploads/</a></li> <li><a href="https://stackoverflow.com/questions/5582516/django-file-upload">Django File Upload</a></li> <li><a href="https://stackoverflow.com/questions/5871730/need-a-minimal-django-file-upload-example">Need a minimal Django file upload example</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload