2011-03-18 13 views
1

私のサイトで問題が発生しています。 私がこれに遭遇したのは初めてで、なぜ誰かが何らかの理由で光を放つことができますか?django ValueError:基数10のint()のリテラルが無効です。 '

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

答えて

3

count空の文字列です。 countが非整数文字列である可能性を補う必要があります。

+0

メッセージありがとうございます。代わりに、私は試して回避策を実行します。 – ApPeL

0

テンプレートのURLを確認する必要があります。 urlがテンプレート内に整数値を持つ必要があるため、整数IDをurl {{user.id}}に渡す必要があります。 Ex。 url: - /polls/{{user.id}}/

テンプレートでは、まずテンプレートID sdhajdhgsjgd {{user.id}} kejhksdbjfのどこかでIDを取得するかどうかをチェックし、ない。

これは他の人にも役立ちます。

関連する問題