Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django ValueError:以10为底的int()的文本无效:'';_Python_Django_Django Views_Django Templates - Fatal编程技术网

Python django ValueError:以10为底的int()的文本无效:'';

Python django ValueError:以10为底的int()的文本无效:'';,python,django,django-views,django-templates,Python,Django,Django Views,Django Templates,我的网站有问题,经常收到这个错误。 这是我第一次遇到这种情况,也许有人能解释一下原因 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) F

我的网站有问题,经常收到这个错误。 这是我第一次遇到这种情况,也许有人能解释一下原因

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
可能是非整数字符串的可能性。

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

在模板中,首先检查获取id是否与模板类型sdhajdhgsjgd{{{user.id}}kejhksdbjf中的任何地方相同,并检查是否获取整数值


希望这对其他人有用。

谢谢您的留言。那我就试着做一个变通办法。