Reputation: 367
I recently started a Django project using Jython. I created a virtualenv and successfully created a Django 1.8.6 project, using a JDBC file for SQLite (sqlite-jdbc-3.8.11.2).
I could create a superuser with jython manage.py createsuperuser
, loaded the admin URL and logged in successfully. I even could create another user from the admin. The problems begin when I tried to edit a user. The server cannot render the template of the detailed instance of the user Model.
I have not installed any external apps, nor created an app in the project. I am using django.contrib.auth for the User models and the Django admin default interface.
The initial error I get when I load the /admin/auth/user/1/
is 'unicode' object has no attribute 'tzinfo'
:
AttributeError at /admin/auth/user/1/
'unicode' object has no attribute 'tzinfo'
Request Method: GET
Request URL: http://localhost:8000/admin/auth/user/1/
Django Version: 1.8.6
Exception Type: AttributeError
Exception Value:
'unicode' object has no attribute 'tzinfo'
Exception Location: /home/dmunoz/jsnmp/Lib/site-packages/django/utils/timezone.py in is_aware, line 337
Python Executable: /home/dmunoz/jsnmp/bin/jython
Python Version: 2.7.0
Python Path:
['/home/dmunoz/snmp/webswitcher',
'/home/dmunoz/jsnmp/Lib/site-packages/django_jython-1.8.0b3-py2.7.egg',
'/home/dmunoz/jsnmp/Lib/site-packages',
'/home/dmunoz/jsnmp/Lib',
'/home/dmunoz/opt/jython2.7.0/Lib',
'__classpath__',
'__pyclasspath__/']
Server time: Tue, 10 Nov 2015 12:31:09 -0300
Error during template rendering
In template /home/dmunoz/jsnmp/Lib/site-packages/django/contrib/admin/templates/admin/includes/fieldset.html, error at line 19
Because of this, I tried setting USE_TZ = False
in the settings.py file. Then, I got 'unicode' object has no attribute 'date'
:
AttributeError at /admin/auth/user/1/
'unicode' object has no attribute 'date'
Request Method: GET
Request URL: http://localhost:8000/admin/auth/user/1/
Django Version: 1.8.6
Exception Type: AttributeError
Exception Value:
'unicode' object has no attribute 'date'
Exception Location: /home/dmunoz/jsnmp/Lib/site-packages/django/forms/widgets.py in decompress, line 888
Python Executable: /home/dmunoz/jsnmp/bin/jython
Python Version: 2.7.0
Python Path:
['/home/dmunoz/snmp/webswitcher',
'/home/dmunoz/jsnmp/Lib/site-packages/django_jython-1.8.0b3-py2.7.egg',
'/home/dmunoz/jsnmp/Lib/site-packages',
'/home/dmunoz/jsnmp/Lib',
'/home/dmunoz/opt/jython2.7.0/Lib',
'__classpath__',
'__pyclasspath__/']
Server time: Tue, 10 Nov 2015 12:28:18 -0300
Error during template rendering
In template /home/dmunoz/jsnmp/Lib/site-packages/django/contrib/admin/templates/admin/includes/fieldset.html, error at line 19
The final error I have got is when I tried to dump the data from auth.User model with jython manage.py dumpdata auth.User --indent=4 --traceback
:
[Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/dmunoz/jsnmp/Lib/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/home/dmunoz/jsnmp/Lib/site-packages/django/core/management/__init__.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/dmunoz/jsnmp/Lib/site-packages/django/core/management/base.py", line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/dmunoz/jsnmp/Lib/site-packages/django/core/management/base.py", line 445, in execute
output = self.handle(*args, **options)
File "/home/dmunoz/jsnmp/Lib/site-packages/django/core/management/commands/dumpdata.py", line 159, in handle
serializers.serialize(format, get_objects(), indent=indent,
File "/home/dmunoz/jsnmp/Lib/site-packages/django/core/serializers/__init__.py", line 129, in serialize
s.serialize(queryset, **options)
File "/home/dmunoz/jsnmp/Lib/site-packages/django/core/serializers/base.py", line 61, in serialize
self.handle_field(obj, field)
File "/home/dmunoz/jsnmp/Lib/site-packages/django/core/serializers/python.py", line 55, in handle_field
self._current[field.name] = field.value_to_string(obj)
File "/home/dmunoz/jsnmp/Lib/site-packages/django/db/models/fields/__init__.py", line 1487, in value_to_string
return '' if val is None else val.isoformat()
AttributeError: 'unicode' object has no attribute 'isoformat'
Python version: 2.7.0, Jython version: 2.7.0, Django version: 1.8.6, django-jython version: 1.8.0b3, SQLITE JDBC version: 3.8.11.2
EDIT:
I created a Django App, with a single and simple model:
from django.db import models
class PMV(models.Model):
creation_date = models.DateField()
I created an instance in the admin web page, with Date = today. When I tried to edit it, I got this:
After this, I added a models.DateTimeField()
to the PMV model, created an instance and tried to edit it. I got the 'unicode' object has no attribute 'tzinfo'
error again.
Upvotes: 1
Views: 306
Reputation: 399
I think this can be readily explained:
Note there is an outstanding bug to add complete sqlite3 support to Jython. I just adjusted the milestone for that bug to 2.7.2 (could be later). Such support is something we have wanted to do for a while, although it's a bit complicated because it's not just a question of using JDBC.
For the time being, this likely means you would to either do your own workaround (don't know scope); or switch to a database like MySQL or Apache Derby (small footprint like sqlite3, but with support for datetimes).
Upvotes: 2