Django is consistently throwing a ValueError on every POST request to the server. From cruising around forms and SE, it seems like this an issue with my Django models. However, I'm not sure why the models would throw this error or why they would be called by Django since this is thrown in a POST event.
View in question:
def channel(request, channel):
user_form = weblog_userForm(request.POST or None)
if request.method == 'POST' and user_form.is_valid():
nickname = user_form.cleaned_data['nickname']
message = user_form.cleaned_data['message']
password = user_form.cleaned_data['password']
postDetails = {}
... process request and eventually ...
return HttpResponse(json.dumps(postDetails), content_type="application/json")
My application models:
class Line(models.Model):
message = models.TextField(blank=True, default="")
nick = models.CharField(max_length=50)
hostname = models.CharField(max_length=300)
channel = models.CharField(max_length=200)
timestamp = models.DateTimeField(auto_now_add=True)
LINE_TYPES = (
('PMSG', 'PRIVMSG'),
('SMSG', 'SOCKETMSG'),
('WMSG', 'WEBMSG'),
('NTCE', 'NOTICE'),
('ACTN', 'ACTION'),
('JOIN', 'JOIN'),
('PART', 'PART'),
('QUIT', 'QUIT'),
('NICK', 'NICK'),
('TPIC', 'TOPIC'),
)
msgType = models.CharField(max_length=4, choices=LINE_TYPES, default='PRIVMSG')
def __str__(self):
return self.message
class banned_ips(models.Model):
bannedIp = models.GenericIPAddressField()
Traceback:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/django/weblogs/log/views.py", line 96, in channel
json_data = serializers.serialize("json", list(reversed(Line.objects.filter(id__gt=latest_line_id, channel=channel).order_by('-id')[:100])))
File "/usr/local/lib/python3.5/dist-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 836, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 854, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/query.py", line 1252, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/query.py", line 1276, in _add_q
split_subq=split_subq,
File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/query.py", line 1214, in build_filter
condition = self.build_lookup(lookups, col, value)
File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/query.py", line 1084, in build_lookup
lookup = lookup_class(lhs, rhs)
File "/usr/local/lib/python3.5/dist-packages/django/db/models/lookups.py", line 18, in __init__
self.rhs = self.get_prep_lookup()
File "/usr/local/lib/python3.5/dist-packages/django/db/models/lookups.py", line 68, in get_prep_lookup
return self.lhs.output_field.get_prep_value(self.rhs)
File "/usr/local/lib/python3.5/dist-packages/django/db/models/fields/__init__.py", line 947, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: ''
Any help or ideas would be appreciated, really scratching my head on this one.
File "/home/django/weblogs/log/views.py", line 96, in channel,json_data = serializers.serialize("json", list(reversed(Line.objects.filter(id__gt=latest_line_id, channel=channel).order_by('-id')[:100])))- schrodigerscatcuriositylatest_line_id? The traceback suggests it may not be an integer, causing the error. - VMatić