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.
Related
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
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
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"
im using sorl-thumbnail for Django and I found a bug:
Internal Server Error: /history/company/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 111, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/srv/mysite/mysite/mysite/history/views.py", line 39, in company_history_view
context_instance=RequestContext(request),
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts.py", line 23, in render_to_response
return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 178, in render_to_string
return t.render(context_instance)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 148, in render
return self._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 142, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 844, in render
bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 80, in render_node
return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 126, in render
return compiled_parent._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 142, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 844, in render
bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 80, in render_node
return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 65, in render
result = block.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 844, in render
bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 80, in render_node
return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py", line 312, in render
return nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 844, in render
bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 80, in render_node
return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py", line 201, in render
nodelist.append(node.render(context))
File "/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py", line 312, in render
return nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 844, in render
bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 80, in render_node
return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/sorl/thumbnail/templatetags/thumbnail.py", line 58, in render
return self._render(context)
File "/usr/local/lib/python2.7/dist-packages/sorl/thumbnail/templatetags/thumbnail.py", line 136, in _render
thumbnail = get_thumbnail(file_, geometry, **options)
File "/usr/local/lib/python2.7/dist-packages/sorl/thumbnail/shortcuts.py", line 8, in get_thumbnail
return default.backend.get_thumbnail(file_, geometry_string, **options)
File "/usr/local/lib/python2.7/dist-packages/sorl/thumbnail/base.py", line 118, in get_thumbnail
thumbnail)
File "/usr/local/lib/python2.7/dist-packages/sorl/thumbnail/base.py", line 151, in _create_thumbnail
default.engine.write(image, options, thumbnail)
File "/usr/local/lib/python2.7/dist-packages/sorl/thumbnail/engines/base.py", line 142, in write
progressive=progressive
File "/usr/local/lib/python2.7/dist-packages/sorl/thumbnail/engines/pil_engine.py", line 223, in _get_raw_data
image.save(bf, **params)
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1685, in save
save_handler(self, fp, filename)
File "/usr/local/lib/python2.7/dist-packages/PIL/JpegImagePlugin.py", line 696, in _save
ImageFile._save(im, fp, [("jpeg", (0, 0)+im.size, 0, rawmode)], bufsize)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFile.py", line 473, in _save
e = Image._getencoder(im.mode, e, a, im.encoderconfig)
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 430, in _getencoder
return encoder(mode, *args + extra)
TypeError: integer argument expected, got float
I don't know if it's a sorl-thumbnail bug or a PILLOW bug.
I also dont know which parameter failed. How can I figure this out?
Should I start debugging?
Thanks!
Edit 1:
Started debbugin and the last parameters are:
encoder = <built-in function jpeg_encoder>
args = ('RGB',)
mode = 'RGB'
encoder_name = 'jpeg'
extra = (95, True, 0, True, 0, 0.0, 0.0, -1, None, '', '')
Edit 2:
In /usr/local/lib/python2.7/dist-packages/PIL/Image.py in save at line 1685:
save_handler(self, fp, filename) - parameter are:
fp = <cStringIO.StringO object at 0x7f0d4f3ae688>
format = 'JPEG'
self = <PIL.Image.Image image mode=RGB size=75x21 at 0x7F0D4F2079E0>
filename = ''
ext = ''
params = {'compression': 0, 'dpi': (0.0, 0.0),'optimize': 1, 'progressive': True, 'quality': 95}
close = 0
save_handler = <function _save at 0x7f0d4f13d230>
They look normal to me, maybe is a PILLOW bug.
Found the reason:
File Type: PC bitmap, Windows 3.x format, 285 x 78 x 24
MIME Type: image/x-ms-bmp
Suggested file extension(s): bmp
The file is a BMP, not a JPG.
Sorry.
I've tried to build the simplest possible form in Sprox using pyramid.
# model.py
class Allocation:
# some fields ...
class SproxForm(AddRecordForm):
__model__ = Allocation
sprox_form = SproxForm(DBSession)
# views.py
#view_config(route_name='sprox_add', renderer='templates/sprox.pt')
def sprox_form_add(request):
return {'form':sprox_form,'form_input':{}}
<!-- sprox.pt -->
<html>
<body>
<div tal:content="structure form(form_input)"/>
</body>
</html>
When I navigate to that view in the browser, I get
Traceback (most recent call last):
File "D:\prg\py2\lib\site-packages\pyramid_debugtoolbar-1.0.4-py2.7.egg\pyramid_debugtoolbar\panels\performance.py", line 69, in noresource_timer_handler
result = handler(request)
File "D:\prg\py2\lib\site-packages\pyramid\tweens.py", line 21, in excview_tween
response = handler(request)
File "D:\prg\py2\lib\site-packages\pyramid_tm-0.7-py2.7.egg\pyramid_tm\__init__.py", line 82, in tm_tween
reraise(*exc_info)
File "D:\prg\py2\lib\site-packages\pyramid_tm-0.7-py2.7.egg\pyramid_tm\__init__.py", line 63, in tm_tween
response = handler(request)
File "D:\prg\py2\lib\site-packages\pyramid\router.py", line 161, in handle_request
response = view_callable(context, request)
File "D:\prg\py2\lib\site-packages\pyramid\config\views.py", line 367, in rendered_view
context)
File "D:\prg\py2\lib\site-packages\pyramid\renderers.py", line 531, in render_view
return self.render_to_response(response, system, request=request)
File "D:\prg\py2\lib\site-packages\pyramid\renderers.py", line 561, in render_to_response
result = self.render(value, system_values, request=request)
File "D:\prg\py2\lib\site-packages\pyramid\renderers.py", line 557, in render
result = renderer(value, system_values)
File "D:\prg\py2\lib\site-packages\pyramid\chameleon_zpt.py", line 42, in __call__
result = self.template(**system)
File "D:\prg\py2\lib\site-packages\chameleon\template.py", line 125, in __call__
return self.render(**kwargs)
File "D:\prg\py2\lib\site-packages\chameleon\zpt\template.py", line 257, in render
return super(PageTemplate, self).render(**vars)
File "D:\prg\py2\lib\site-packages\chameleon\template.py", line 190, in render
raise_with_traceback(exc, tb)
File "D:\prg\py2\lib\site-packages\chameleon\template.py", line 172, in render
self._render(stream, econtext, rcontext)
File "sprox_3aacd319285f07641f9292cdee192301f3a0bccd.py", line 136, in render
File "D:\prg\py2\lib\site-packages\chameleon\zpt\template.py", line 261, in include
self._render(*args, **kwargs)
File "template_f352de36cd7e76f81188f12078004a91a152cf44.py", line 376, in render
File "sprox_3aacd319285f07641f9292cdee192301f3a0bccd.py", line 106, in __fill_content
File "D:\prg\py2\lib\site-packages\sprox\viewbase.py", line 113, in __call__
return self.display(*args, **kw)
File "D:\prg\py2\lib\site-packages\sprox\viewbase.py", line 119, in display
return self.__widget__.display(*args, **kw)
File "D:\prg\py2\lib\site-packages\tw2\core\widgets.py", line 438, in display
return self.generate_output(displays_on)
File "D:\prg\py2\lib\site-packages\tw2\core\widgets.py", line 475, in generate_output
mw,
File "D:\prg\py2\lib\site-packages\tw2\core\templating.py", line 204, in render
return callback(kwargs)
File "D:\prg\py2\lib\site-packages\tw2\core\templating.py", line 144, in <lambda>
return lambda kwargs: Markup(tmpl.render(**kwargs))
File "D:\prg\py2\lib\site-packages\mako\template.py", line 412, in render
return runtime._render(self, self.callable_, args, data)
File "D:\prg\py2\lib\site-packages\mako\runtime.py", line 766, in _render
**_kwargs_for_callable(callable_, data))
File "D:\prg\py2\lib\site-packages\mako\runtime.py", line 798, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "D:\prg\py2\lib\site-packages\mako\runtime.py", line 824, in _exec_template
callable_(context, *args, **kwargs)
File "form_mak", line 49, in render_body
File "D:\prg\py2\lib\site-packages\tw2\core\widgets.py", line 436, in display
r.prepare()
File "D:\prg\py2\lib\site-packages\tw2\core\resources.py", line 165, in prepare
resources = rl['middleware'].resources
KeyError: 'middleware'
- Expression: "form(form_input)"
- Filename: d:\prg\py2\awsalloc2\awsalloc2\templates\sprox.pt
- Location: (9:28)
- Source: ... v tal:content="structure form(form_input)" />
^^^^^^^^^^^^^^^^
- Arguments: repeat: {...} (0)
renderer_name: templates/sprox.pt
req: <Request - at 0x46fceb8L>
form: <SproxForm - at 0x471cb38L>
request: <Request - at 0x46fceb8L>
renderer_info: <RendererHelper - at 0x4a3b7b8L>
context: <instance None at 0x4f93c88L>
form_input: {...} (0)
view: <function sprox_form_add at 0x4a3d278L>
I have no idea what your real problem is, but I threw together a little demo to demonstrate how to setup Sprox under Pyramid. It was somewhat painful and uses some idioms that I consider pretty outdated, including requiring Paste, SQLAlchemy < 0.8, Genshi, and ToscaWidgets < 2.0. Hope this helps.
If I had to guess, you aren't adding the middleware to your app.
app = tw.api.make_middleware(
app,
{
'toscawidgets.framework' : 'wsgi',
'toscawidgets.middleware.inject_resources' : True,
},
stack_registry=True,
)
https://github.com/mmerickel/pyramid_sprox_demo