【问题标题】:django ValueError: invalid literal for int() with base 10: ''django ValueError:以 10 为基数的 int() 的无效文字:''
【发布时间】:2011-07-17 23:43:56
【问题描述】:

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

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,}

【问题讨论】:

    标签: python django django-views django-templates


    【解决方案1】:

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

    【讨论】:

    • 感谢您的留言。我会尝试做一个解决方法。
    【解决方案2】:

    您需要检查模板中的 URL。 您需要将整数 id 传递给 url {{user.id}} 因为 url 需要在模板中具有整数值。 前任。网址:- /polls/{{user.id}}/

    在模板中首先检查您的获取 id 是否像模板类型 sdhajdhgsjgd {{user.id}} kejhksdbjf 中的任何地方一样,然后检查您是否获取整数值。

    希望这对其他人有用。

    【讨论】:

      猜你喜欢
      • 2013-08-04
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2021-11-12
      • 2017-12-06
      • 2018-08-29
      • 1970-01-01
      相关资源
      最近更新 更多