python - File Upload in Mezzanine -
i unable upload file upload program. created small project in django upload , download files. project was/is working fine. trying in mezzanine have created following models:
from django.db import models django.contrib.auth.models import user mezzanine.pages.models import page time import time def get_upload_file_name(instance, filename): return "galleries/%s_%s" %(str(time()).replace('.','_'), filename) gender = (('----','please select ...'),('male','male'), ('female','female')) class allusers(models.model): fullname = models.charfield(max_length=300) dob = models.datefield() gender = models.charfield(max_length=7, choices = gender) homeaddress = models.textfield() contact = models.charfield(max_length=300) email = models.emailfield() cv = models.filefield(upload_to = get_upload_file_name)
forms :
class userform(forms.modelform): class meta: model = allusers fields = ['fullname' ,'dob' ,'gender','homeaddress','contact','email','cv','userdepartment']
html page form
<form action="/users/" method="post" enctype="multipart/form-data">{%csrf_token%} <fieldset> {{id}} <legend>users profile</legend> {% fields_for form %} <div class="form-actions"> {% block account_form_actions %} <input class="btn btn-primary btn-lg pull-right" type="submit" value="submit"> {% endblock %} </div> </fieldset> </form>
problem: upload file , press submit button, on submission moves me html form page , remove file uploaded. , ask me upload file again.
i not deleting question, because may help!
your forms not upload files. no worries. see:
symptom have filefield() , imagefield() fields in form , files not uploaded when submit form
probable cause might missing request.files argument when intantiate form object.
solution make sure passing request.files when intantiate form object:
form = myform(request.post, request.files)
*more details : * https://code.djangoproject.com/wiki/newbiemistakes
Comments
Post a Comment