Wednesday, 15 September 2010

python - TypeError in django when trying to create an upload form -


I am trying to follow the tutorial to create an upload form for my Django app. I am trying to create it, so I can upload a CSV file, then I can process it.

I'm not able to get a TypeError / upload / 'str' object

Upload HTML

   gt; & Lt; A href = "{{upload.csvfile.url}}" {{upload.csvfile.name}} & lt; / A & gt; & Lt; / Li & gt; {% Endfor%} & lt; / Ul & gt; {% Else%} & lt; P & gt; No uploads. & Lt; / P & gt; {% Endif%} & lt ;! - Upload form note antipay feature! - & gt; & Lt; Form action = "{% url 'upload'%}" method = "post" encrypt = "multipart / form-data" & gt; {% Csrf_token%} & lt; P & gt; {{Form.non_field_errors}} & lt; / P & gt; & Lt; P & gt; {{Form.csvfile.label_tag}} {{form.csvfile.help_text}} & lt; / P & gt; & Lt; P & gt; {{Form.csvfile.errors}} {{form.csvfile}} & lt; / P & gt; & Lt; P & gt; & Lt; Input type = "submit" value = "upload" / & gt; & Lt; / P & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

views.py

  DRF upload (request): # Upload request file if request.method == 'POST': form = UploadForm (request POST, request.FILES) form.is_valid (): newdoc = CSV (docfile = request.FILES ['csvfile']) newdoc.save () other: form = UploadForm () # blank, unbound form  < / Pre> 

models.py

  class CSV (models.model): file = models.FileField (upload_to = 'csv /')  

Forms.py

  class UploadForm (forms.Form): csvfile = forms.FileField (label = 'select a CSV file')  

Urls.py

  url (r '^ admin /', include (admin.site.urls)), url (r '^ upload / $', 'upload', name = ' Upload '),  

Any idea why I am getting this error? There is no way to find out what specifically is the debug page?

  Environment: Request method: Get Request URL: http://127.0.0.1:8000/upload/ Django Version: 1.7.6 Python Version: 3.4.2 installed application: ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes',' django.contrib.sessions', 'django.contrib.messages',' django.contrib.staticfiles', 'import_export', 'fanduel') established middleware: ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware' "Djngokcontribkotkmidilveyrkothentikashnmiddlevre 'Djngokcontribkotkmidilveyrkseshnothentikashnmiddlevre' Djngokcontribkmessgeskmidilveyrkmessgemiddlevre 'Djngokmidilveyrkklikjakingkksframeopshansmiddlevre') Traceback: file "C: \ Users \ Wilson \ AppData \ Roaming \ Python \ Python34 \ site-packages \ django \ core \ handlers \ base.py" get_response 111. Response (request = wrapped_callback, * callback_args, ** callback_kwargs) exception type: / upload / exception TypeError: 'str' object is not callable  


No comments:

Post a Comment