Django는 서버에 대한 POST 요청마다 항상 ValueError
을 던집니다. 형태와 SE 주위를 순항하는 것에서부터, 이것은 나의 Django 모델의 문제처럼 보입니다. 그러나, 나는 왜이 모델이이 오류를 던질 것인지, 아니면 장고가 POST 이벤트에 던져지기 때문에 Django가 호출 할 이유를 확신하지 못한다. 문제Django raising ValueError : POST에서 기본 10을 사용하는 int()에 대한 리터럴이 잘못되었습니다.
보기 :
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")
내 응용 프로그램 모델 :
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 (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: ''
어떤 도움이나 아이디어는 정말이 일에 내 머리를 긁적, 주시면 감사하겠습니다 .
오류는'채널 "에있는'/home/django/weblogs/log/views.py"줄 96에서, json_data = serializers.serialize ("json", list (reversed (Line.objects. filter (id__gt = latest_line_id, channel = channel) .order_by ('- id') [)])' –
'latest_line_id'의 값은 무엇입니까? 역 추적은 오류가 발생한 정수가 아닐 수도 있음을 나타냅니다. –