ajax - Decimal('12000') is not JSON serializable -


I have a dijongo example running on Apache 2. One of my webpages is doing an AJAX callback to the project. Most of the time, it works great, but for some reasons I can not determine this, it stops working with Django from the following error:

Decimal ('12000') is not a JSON serial

Once I get this error once, it stops working for ever. I know that the only solution is to start Apache again.

Python / Django is not changing, nor does the data requested by Ajax calls. I never got this problem when I ran my code on Django web server.

@login_required def KPIInitTable (requested): kpi_values ​​= [ob. KPI.Obages '' As_json () for OB in March '' 'table_data': kPI_group, 'callheader': ['kpi', 'citecatcher', 'type', 'jan', 'february' 'April', 'May', 'Jun', 'Jul', 'Aug', 'September', 'Oct', 'Nov', 'Dec' '],' Roha Headers': 0, 'KPIilist': Settings TST_KPILIST, 'TypeList': settings.TST_TYPELIST, 'CityCategoryList': settings.TST_CITYCATEGORYLIST} response = HttpResponse (dump (data, cls = DjangoJSONEncoder), mime type = 'application / json') ['cache-control'] = ' No-Cash Returns Response

Models.py:

  Import Model class from kPI (models.Model): name = models.CharField (Max_length = 50, faucet = true) City Caribbean = Model.Carfild (max_length = 50, Null = tru) type = model.carfield (max_lang = = 20, null = true =) = model. Decimal field (max_digits = 15, decimal_play = 2, zero = true) Feb = model. Decimalfill (max_digits = 15, decimal_partment = 2, zero = true) march = model. May be = models.DecimalField (max_digits = 15, decimal_places = 2, null = true) is the decimal time (max_digits = 15, decimal_places = 2, null = true) April = models.DecimalField (max_digits = 15, decimal_places = 2, null = true) To Jun = models.DecimalField (max_digits = 15, decimal_places = 2, null = true) Jul = models.DecimalField (max_digits = 15, decimal_places = 2, null = true) August = models.DecimalField (max_digits = 15, decimal_places = 2 , Null = this is true) Sep = models.DecimalField (max_digits = 15, decimal_places = 2, null = true) October = models.DecimalField (max_digits = 15, decimal_places = 2, null = true) November = models.DecimalField (max_digits = 15, decimal_places = 2, null = true) Dec = models.DecimalField (max_digits = 15, decimal_places = 2, null = true) uniqueFields = ['name', ("Run_stast", "calculate new targets"), ("validate_tst", "validate"), 'citycatcher', 'type'] class meta: permissions = (("access_tst", "access target target tool.") And load new goal. "),) Def as_json (self): returns {0: self.name, 1: self.CityCategory, 2: self. Type, 3: self. Jan, 4: Self. Fab, 5: self. , 6: self APR, 7: self. May, 8: self Johns, 9: self Joule, 10: self. Eg, 11: self. Separate, 12: self. Oct, 13: self Nova, 14: Self.Dec}  

The value "12000" is actually the first decimal value of the first line restarted by the database (SQLite).

Any thoughts?

thx,

One way to fix the problem is by to_json ( ) Enter all decimal field values ​​for method and str :

  def as_json (auto): return {0: self.name, 1: Self .ctc category, 2: self Type, 3: str (self.jan), 4: str (self.feb), ... 14: str (self.Dec)}  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -