The following code worked fine in Django 1.11, but in DJango 2 and up it fails:
'imageToLoad' : imageQ[0].imagePath
The error is AttributeError: 'ImageFieldFile' object has no attribute 'replace'
imagePath is an ImageField.
I was reading through the DJango 2 documentation but couldn't figure out what the issue is.
Here is the entire code block:
def getContextFromObject(request,imageQ):
if (imageQ != None):
imageJson = serializers.serialize("json", imageQ)
print("image id is " + str(imageQ[0].id))
request.session['image_id'] = imageQ[0].id
print("attempt to load: " + str(imageQ[0].imagePath))
# Below is the block that fails on DJango 2. Specifically, it is the first part, 'imageToLoad' : imageQ[0].imagePath
context = {'imageToLoad' : imageQ[0].imagePath,
'imageWidthPixels': imageQ[0].widthPixels,
'imageHeightPixels': imageQ[0].heightPixels,
'imageMeasuredCenter': (imageQ[0].swMeasuredCenter).quantize(Decimal('.01'), rounding=ROUND_DOWN),
'micronsPerPixel': imageQ[0].micronsPerPixel,
'imageChannelSelect': imageQ[0].channelSelect,
'imageId' : str(imageQ[0].id),
'images' : imageJson
}
else:
context = { }
return context;
Here is the full error traceback:
Traceback (most recent call last):
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\staticfiles\handlers.py", line 66, in __call__
return self.application(environ, start_response)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\wsgi.py", line 146, in __call__
response = self.get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 81, in get_response
response = self._middleware_chain(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
response = response_for_exception(request, exc)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
response = self.get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
response = response_for_exception(request, exc)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
response = self.get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
response = response_for_exception(request, exc)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
response = self.get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
response = response_for_exception(request, exc)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
response = self.get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
response = response_for_exception(request, exc)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
response = self.get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
response = response_for_exception(request, exc)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
response = self.get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
response = response_for_exception(request, exc)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
response = self.get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
response = response_for_exception(request, exc)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\vistagalaxy\images\views.py", line 717, in currentViewing
return render(request, template, context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\shortcuts.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\loader.py", line 62, in render_to_string
return template.render(context, request)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 175, in render
return self._render(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 167, in _render
return self.nodelist.render(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\loader_tags.py", line 155, in render
return compiled_parent._render(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 167, in _render
return self.nodelist.render(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\loader_tags.py", line 67, in render
result = block.nodelist.render(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 943, in render
bit = node.render_annotated(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py", line 910, in render_annotated
return self.render(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\templatetags\static.py", line 106, in render
url = self.url(context)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\templatetags\static.py", line 103, in url
return self.handle_simple(path)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\templatetags\static.py", line 118, in handle_simple
return staticfiles_storage.url(path)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\files\storage.py", line 329, in url
url = filepath_to_uri(name)
File "C:\Users\abharadwaj\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\encoding.py", line 252, in filepath_to_uri
return quote(path.replace("\\", "/"), safe="/~!*()'")
AttributeError: 'ImageFieldFile' object has no attribute 'replace'
[14/Mar/2018 10:47:00] "GET /viewing HTTP/1.1" 500 59
Related
I want to use KMeans in Django... my code is:
from django.db import models
from django.utils import timezone
import sys
from sklearn.cluster import KMeans
from sklearn.metrics import pairwise_distances_argmin_min
# Create your models here.
class tabla (models.Model):
nombre = models.CharField(max_length=35)
comida = models.PositiveSmallIntegerField()
cantidad = models.PositiveSmallIntegerField()
edad = models.PositiveSmallIntegerField()
fecha_publicacion = models.DateTimeField(auto_now_add = True)
def datos(self):
cadena="hola, {0}, {1}, {2}, {3}, {4}"
cadena2="{0} {1} {2}"
cadena2.format(self.cantidad,self.comida,self.edad)
#return cadena.format(self.nombre, self.comida,self.cantidad,self.edad,self.fecha_publicacion)
kmeans = KMeans(n_clusters=3).fit(cadena2)
centroids = kmeans.cluster_centers_
return centroids
def __str__(self):
return self.datos()
and .. my result is: oh my problem is ...
what is the wrong??
C:\TrabajoIA>python manage.py runserver
C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py:47: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py:47: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
Performing system checks...
System check identified no issues (0 silenced).
December 17, 2018 - 04:46:40
Django version 2.1.3, using settings 'TrabajoIA.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py:47: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
Performing system checks...
System check identified no issues (0 silenced).
December 17, 2018 - 04:50:53
Django version 2.1.3, using settings 'TrabajoIA.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Internal Server Error: /admin/Gestion/tabla/
Traceback (most recent call last):
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\models\options.py", line 564, in get_field
return self.fields_map[field_name]
KeyError: '__str__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\utils.py", line 278, in lookup_field
f = _get_non_gfk_field(opts, name)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\utils.py", line 309, in _get_non_gfk_field
field = opts.get_field(name)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\models\options.py", line 566, in get_field
raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: tabla has no field named '__str__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\core\handlers\base.py", line 156, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\core\handlers\base.py", line 154, in _get_response
response = response.render()
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\response.py", line 106, in render
self.content = self.rendered_content
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\response.py", line 83, in rendered_content
content = template.render(context, self._request)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 171, in render
return self._render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\templatetags\base.py", line 33, in render
return super().render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\library.py", line 214, in render
_dict = self.func(*resolved_args, **resolved_kwargs)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\templatetags\admin_list.py", line 341, in result_list
'results': list(results(cl))}
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\templatetags\admin_list.py", line 318, in results
yield ResultList(None, items_for_result(cl, res, None))
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\templatetags\admin_list.py", line 309, in __init__
super().__init__(*items)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\templatetags\admin_list.py", line 228, in items_for_result
f, attr, value = lookup_field(field_name, result, cl.model_admin)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\utils.py", line 291, in lookup_field
value = attr()
File "C:\TrabajoIA\TrabajoIA\Apps\Gestion\models.py", line 28, in __str__
return self.datos()
File "C:\TrabajoIA\TrabajoIA\Apps\Gestion\models.py", line 23, in datos
kmeans = KMeans(n_clusters=3).fit(cadena2)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\cluster\k_means_.py", line 968, in fit
return_n_iter=True)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\cluster\k_means_.py", line 311, in k_means
order=order, copy=copy_x)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\utils\validation.py", line 522, in check_array
array = np.asarray(array, dtype=dtype, order=order)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\numeric.py", line 501, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: could not convert string to float: '{0} {1} {2}'
[17/Dec/2018 04:51:07] "GET /admin/Gestion/tabla/ HTTP/1.1" 500 316834
Internal Server Error: /admin/Gestion/tabla/
Traceback (most recent call last):
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\models\options.py", line 564, in get_field
return self.fields_map[field_name]
KeyError: '__str__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\utils.py", line 278, in lookup_field
f = _get_non_gfk_field(opts, name)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\utils.py", line 309, in _get_non_gfk_field
field = opts.get_field(name)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\models\options.py", line 566, in get_field
raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: tabla has no field named '__str__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\core\handlers\base.py", line 156, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\core\handlers\base.py", line 154, in _get_response
response = response.render()
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\response.py", line 106, in render
self.content = self.rendered_content
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\response.py", line 83, in rendered_content
content = template.render(context, self._request)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 171, in render
return self._render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\templatetags\base.py", line 33, in render
return super().render(context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\template\library.py", line 214, in render
_dict = self.func(*resolved_args, **resolved_kwargs)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\templatetags\admin_list.py", line 341, in result_list
'results': list(results(cl))}
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\templatetags\admin_list.py", line 318, in results
yield ResultList(None, items_for_result(cl, res, None))
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\templatetags\admin_list.py", line 309, in __init__
super().__init__(*items)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\templatetags\admin_list.py", line 228, in items_for_result
f, attr, value = lookup_field(field_name, result, cl.model_admin)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\contrib\admin\utils.py", line 291, in lookup_field
value = attr()
File "C:\TrabajoIA\TrabajoIA\Apps\Gestion\models.py", line 28, in __str__
return self.datos()
File "C:\TrabajoIA\TrabajoIA\Apps\Gestion\models.py", line 23, in datos
kmeans = KMeans(n_clusters=3).fit(cadena2)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\cluster\k_means_.py", line 968, in fit
return_n_iter=True)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\cluster\k_means_.py", line 311, in k_means
order=order, copy=copy_x)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\utils\validation.py", line 522, in check_array
array = np.asarray(array, dtype=dtype, order=order)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\numeric.py", line 501, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: could not convert string to float: '{0} {1} {2}'
[17/Dec/2018 04:51:09] "GET /admin/Gestion/tabla/ HTTP/1.1" 500 316804
I see wath ...the main problem is :
ValueError: could not convert string to float: '{0} {1} {2}'
[17/Dec/2018 04:51:09] "GET /admin/Gestion/tabla/ HTTP/1.1" 500 316804
well...
how to convert that string into a string but of decimal numbers ... something like: [[1], [2], [3]], ... or something very similar to that (this part does not know how to do it)
KMeans requires you to pass an array-like object whereas it looks like you're passing strings. You could try replacing
cadena2="{0} {1} {2}"
cadena2.format(self.cantidad,self.comida,self.edad)
with
cadena2 = [self.cantidad,self.comida,self.edad].
Which will work assuming the items in the list (self.cantidad,self.comida,self.edad) are numeric and not strings.
I have been trying to get this theme working for Open edX (based on Django) and I am getting this error in supervisor logs -
AttributeError: 'CourseOverview' object has no attribute 'start_datetime_text'
The whole error is this -
May 14 11:43:36 ip-172-26-15-154 [service_variant=lms][django.request][env:sandbox] ERROR [ip-172-26-15-154 20450] [base.py:256] - Internal Server Error: /
Traceback (most recent call last):
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 145, in inner
return func(*args, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 110, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/edx/app/edxapp/edx-platform/common/djangoapps/util/cache.py", line 78, in wrapper
response = view_func(request, *args, **kwargs)
File "/edx/app/edxapp/edx-platform/lms/djangoapps/branding/views.py", line 94, in index
return student.views.index(request, user=request.user)
File "/edx/app/edxapp/edx-platform/common/djangoapps/student/views.py", line 221, in index
return render_to_response('index.html', context)
File "/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/shortcuts.py", line 198, in render_to_response
return HttpResponse(render_to_string(template_name, dictionary, context_instance, namespace, request), **kwargs)
File "/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/shortcuts.py", line 188, in render_to_string
return template.render_unicode(**context_dictionary)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/template.py", line 454, in render_unicode
as_unicode=True)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 829, in _render
**_kwargs_for_callable(callable_, data))
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 864, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 890, in _exec_template
callable_(context, *args, **kwargs)
File "/tmp/mako_lms/c11f9c5f254718c770fcf021e95ac093/main.html.py", line 286, in render_body
__M_writer(filters.decode.utf8(self.body()))
File "/tmp/mako_lms/c11f9c5f254718c770fcf021e95ac093/marvel-theme-eucalyptus/lms/templates/index.html.py", line 54, in render_body
runtime._include_file(context, (courses_list), _template_uri)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 752, in _include_file
callable_(ctx, **_kwargs_for_include(callable_, context._data, **kwargs))
File "/tmp/mako_lms/c11f9c5f254718c770fcf021e95ac093/marvel-theme-eucalyptus/lms/templates/courses_list.html.py", line 44, in render_body
runtime._include_file(context, u'course.html', _template_uri, course=course)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 752, in _include_file
callable_(ctx, **_kwargs_for_include(callable_, context._data, **kwargs))
File "/tmp/mako_lms/c11f9c5f254718c770fcf021e95ac093/marvel-theme-eucalyptus/lms/templates/course.html.py", line 60, in render_body
__M_writer(filters.html_escape(filters.decode.utf8(course.start_datetime_text())))
AttributeError: 'CourseOverview' object has no attribute 'start_datetime_text'
The file in question (the one that is giving the error - course.html.py) is here
https://pastebin.com/0S79hhDa
The start_datetime_text method was removed on november 30, 2016.
You should be using course.advertised_start. You can see the current version of the course.html template
MySQLdb raises execute() first error.
How do I fix it?
def update_query_extendNum(cls,params):
print params
sqlString = "REPLACE INTO editor_query(id,extend_num) values(%s,%s)"
cursor = connection.cursor()
cursor.executemany(sqlString,params)
querys = cursor.fetchall()
cursor.close()
return querys
Error:
File "C:\Python27\lib\site-packages\django\core\handlers\exception.py", line 39, in inner response = get_response(request)
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response response = self.process_exception_by_middleware(e, request)
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\work\test\editor\chat_test_service\editor\api.py", line 162, in updataTask update_query = QueryService.update_query_extendNum([('02f0698462344c9299a93fea2d97b34e',11),('0350d8dcb58e48448f6d9fbabc06a43c',111)])
File "C:\work\test\editor\chat_test_service\editor\service.py", line 58, in update_query_extendNum return dao.QueryDao.update_query_extendNum(params)
File "C:\work\test\editor\chat_test_service\editor\dao.py", line 109, in update_query_extendNum querys = cursor.fetchall()
File "C:\Python27\lib\site-packages\django\db\utils.py", line 101, in inner return func(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 94, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 101, in inner return func(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQL`enter code here`db\cursors.py", line 382, in fetchall self._check_executed()
File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 105, in _check_executed self.errorhandler(self, ProgrammingError, "execute() first")
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue ProgrammingError: execute() first
I am trying to update a self datetime field of a model using F() object in django.
HeatWatchList.objects.filter(
user=request.user,
next_date_to__lt=datetime.combine(datetime.now().date(), time.min)
).update(
next_date_from = F('next_date_from') + relativedelta(months=1),
next_date_to = F('next_date_to') + relativedelta(months=1)
)
But when doing this i got AttributeError: relativedelta object has no attribute translate.
Here is the traceback i got when executing the code maybe it has an issue using the F() object when adding value with a datetime type relativedelta.
Traceback (most recent call last):
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
response = get_response(request)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\django\views\decorators\csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\rest_framework\viewsets.py", line 83, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\rest_framework\views.py", line 477, in dispatch
response = self.handle_exception(exc)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\rest_framework\views.py", line 437, in handle_exception
self.raise_uncaught_exception(exc)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\rest_framework\views.py", line 474, in dispatch
response = handler(request, *args, **kwargs)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\farm_management\heat\views.py", line 192, in update_watchlist
next_date_to = F('next_date_to') + relativedelta(months=1)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\django\db\models\query.py", line 637, in update
rows = query.get_compiler(self.db).execute_sql(CURSOR)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\django\db\models\sql\compiler.py", line 1148, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\django\db\models\sql\compiler.py", line 835, in execute_sql
cursor.execute(sql, params)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\django\db\backends\mysql\base.py", line 110, in execute
return self.cursor.execute(query, args)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\pymysql\cursors.py", line 164, in execute
query = self.mogrify(query, args)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\pymysql\cursors.py", line 143, in mogrify
query = query % self._escape_args(args, conn)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\pymysql\cursors.py", line 118, in _escape_args
return tuple(conn.literal(arg) for arg in args)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\pymysql\cursors.py", line 118, in <genexpr>
return tuple(conn.literal(arg) for arg in args)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\pymysql\connections.py", line 800, in literal
return self.escape(obj, self.encoders)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\pymysql\connections.py", line 793, in escape
return escape_item(obj, self.charset, mapping=mapping)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\pymysql\converters.py", line 27, in escape_item
val = encoder(val, mapping)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\pymysql\converters.py", line 110, in escape_unicode
return u"'%s'" % _escape_unicode(value)
File "C:\Users\Web\Desktop\PyDev\Envs\djangular\lib\site-packages\pymysql\converters.py", line 73, in _escape_unicode
return value.translate(_escape_table)
AttributeError: 'relativedelta' object has no attribute 'translate'
Seems like pymysql's converters does not support relativedelta objects.
One possible solution is to iterate over objects and update it (inefficient):
objects_list = HeatWatchList.objects.filter(
user=request.user,
next_date_to__lt=datetime.combine(datetime.now().date(), time.min)
)
for obj in object_list:
obj.next_date_from = onj.next_date_from + relativedelta(months=1)
obj.next_date_to = onj.next_date_to + relativedelta(months=1)
objsave()
Or better use datetime.timedelta instead of relativedelta if it possible:
HeatWatchList.objects.filter(
user=request.user,
next_date_to__lt=datetime.combine(datetime.now().date(), time.min)
).update(
next_date_from = F('next_date_from') + timedelta(days=31),
next_date_to = F('next_date_to') + timedelta(days=31)
)
I'm getting a "TemplateSyntaxError: Could not parse the remainder:" here: https://docs.djangoproject.com/en/1.7/intro/tutorial05/
>>> response = client.get(reverse('polls:index'))
gets me this:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Python/2.7/site-packages/django/test/client.py", line 470, in get
**extra)
File "/Library/Python/2.7/site-packages/django/test/client.py", line 286, in get
return self.generic('GET', path, secure=secure, **r)
File "/Library/Python/2.7/site-packages/django/test/client.py", line 358, in generic
return self.request(**r)
File "/Library/Python/2.7/site-packages/django/test/client.py", line 440, in request
six.reraise(*exc_info)
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 137, in get_response
response = response.render()
File "/Library/Python/2.7/site-packages/django/template/response.py", line 103, in render
self.content = self.rendered_content
File "/Library/Python/2.7/site-packages/django/template/response.py", line 78, in rendered_content
template = self.resolve_template(self.template_name)
File "/Library/Python/2.7/site-packages/django/template/response.py", line 54, in resolve_template
return loader.select_template(template)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 188, in select_template
return get_template(template_name, dirs)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 144, in get_template
template, origin = find_template(template_name, dirs)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 132, in find_template
source, display_name = loader(name, dirs)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 44, in __call__
return self.load_template(template_name, template_dirs)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 50, in load_template
template = get_template_from_string(source, origin, template_name)
File "/Library/Python/2.7/site-packages/django/template/loader.py", line 156, in get_template_from_string
return Template(source, origin, name)
File "/Library/Python/2.7/site-packages/django/template/base.py", line 132, in __init__
self.nodelist = compile_string(template_string, origin)
File "/Library/Python/2.7/site-packages/django/template/base.py", line 162, in compile_string
return parser.parse()
File "/Library/Python/2.7/site-packages/django/template/base.py", line 290, in parse
compiled_result = compile_func(self, token)
File "/Library/Python/2.7/site-packages/django/template/defaulttags.py", line 975, in do_if
nodelist = parser.parse(('elif', 'else', 'endif'))
File "/Library/Python/2.7/site-packages/django/template/base.py", line 290, in parse
compiled_result = compile_func(self, token)
File "/Library/Python/2.7/site-packages/django/template/defaulttags.py", line 833, in do_for
nodelist_loop = parser.parse(('empty', 'endfor',))
File "/Library/Python/2.7/site-packages/django/template/base.py", line 290, in parse
compiled_result = compile_func(self, token)
File "/Library/Python/2.7/site-packages/django/template/defaulttags.py", line 1345, in url
viewname = parser.compile_filter(bits[1])
File "/Library/Python/2.7/site-packages/django/template/base.py", line 372, in compile_filter
return FilterExpression(token, self)
File "/Library/Python/2.7/site-packages/django/template/base.py", line 588, in __init__
"from '%s'" % (token[upto:], token))
TemplateSyntaxError: Could not parse the remainder: '\u2018polls:detail\u2019' from '\u2018polls:detail\u2019'
How to resolve this ?
You are using left quote and right quote characters when quoting the view name; where you should be using single or double quotes.
Use either 'polls:details' or "polls:details"