python - Django model form not producing expected HTML -


i have modelform doesn't produce (some of) html (should) represent model fields. can see output @ bottom, it's outputting blank line should outputting title , presumably browse button (or something--right?) filefield.

#views.py def upload_file(request):     if request.method == 'post':         form = uploadfileform(request.post, request.files)     else:         form = uploadfileform()     return render_to_response('files/upload_file.html', { 'form': form })  #models.py django import forms django.db import models django.forms import modelform  class uploadfile(models.model):     title = forms.charfield(max_length = 50)     thefile = forms.filefield()      def __unicode__(self):         return str(title)  class uploadfileform(modelform):     class meta:         model = uploadfile  #upload_file.html <form action="" method="post" enctype="multipart/form-data">     {{ form }}     <input type="submit" value="upload file"> </form>  #the html output <form action="" method="post" enctype="multipart/form-data">      <input type="submit" value="upload file"> </form> 

actually on second thought mistake in declaring model uploadfile (after doublechecking due lack of response). supposed use models.charfield not forms.charfield. model doesn't have content; hence modelform doesn't have fields (it didn't arise error in case advanced user wanted attach form fields wanted use model). need give filefield upload_to location, principally media directory.

class uploadfile(models.model):     title = models.charfield(max_length = 50)     thefile = models.filefield(upload_to="files/")      def __unicode__(self):         return str(title) 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -