Friday, 15 January 2010

File upload and download using Django 1.5 python 2.7.5 -



File upload and download using Django 1.5 python 2.7.5 -

i new django , trying incorporate file upload , file download user. can help me simple code because can't seem understand solutions other topics. thanks!

* got upload work

views.py

def upload(request): if request.method == 'post': form = documentform(request.post, request.files) if form.is_valid(): newdoc = document(docfile = request.files['docfile']) newdoc.save() else: form = documentform()

html

<form action="#" method="post" enctype="multipart/form-data"> {% csrf_token %} <p>{{ form.non_field_errors }}</p> <p>{{ form.docfile.label_tag }} {{ form.docfile.help_text }}</p> <p> {{ form.docfile.errors }} {{ form.docfile }} </p> <p><input type="submit" value="upload" /></p> </form>

models.py

from django.db import models class document(models.model): docfile = models.filefield(upload_to='documents')

forms.py

from django import forms class documentform(forms.form): docfile = forms.filefield( label='select file', help_text='max. 42 megabytes' )

python django file-upload download

No comments:

Post a Comment