django ValueError: 基数为 10 的 int() 文字无效:'' [英] django ValueError: invalid literal for int() with base 10: ''

查看:29
本文介绍了django ValueError: 基数为 10 的 int() 文字无效:''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站有问题,经常收到此错误.这是我第一次遇到这种情况,也许有人可以解释为什么?

I have an issue with my site, receiving this error pretty often. It's the first time i've run into this and maybe someone can shed some light as to why?

Traceback (most recent call last):

File "/opt/python2.6/lib/python2.6/site-packages/django/core/handlers/base.py", line 92, in get_response
response = callback(request, *callback_args, **callback_kwargs)

File "/www/django_test1/fundedbyme/project/views.py", line 194, in browse
items = Project.objects.filter(categories__slug=cat_name, status='AP')[:count]

File "/opt/python2.6/lib/python2.6/site-packages/django/db/models/query.py", line 151, in __getitem__
stop = int(k.stop)

ValueError: invalid literal for int() with base 10: ''

这是我的观点.

def browse(request, template_name='projects/browse.html'):
    cat_name = request.GET.get('category', None)
    city_name = request.GET.get('city', None)
    count = request.GET.get('count','12')
    if cat_name is not None:
        items = Project.objects.filter(categories__slug=cat_name, status='AP')[:count]
        category = get_object_or_None(Category, slug=cat_name)
    if city_name is not None:
        items = Project.objects.filter(location_slug=city_name, status='AP')[:count]
        category = Project.objects.filter(location_slug=city_name, status='AP')[:1]
        category = category[0].location
    total = items.count()
    new_count = int(count) + 12

    context = {'items':items,'cat_name':category,'total':total,'new_count':new_count,}

推荐答案

count 是空字符串.您需要补偿 count 可能是非整数字符串的可能性.

count is the empty string. You need to compensate for the possibility that count could be a non-integer string.

这篇关于django ValueError: 基数为 10 的 int() 文字无效:''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆