2011-12-23 73 views
0

當我訪問此網址:獲取ValueError異常的響應Django框架HTTP請求

http://localhost:8000/ProjectOverview/proj_view/15/ 

Django的告訴我,格式爲完成:

Request Method:  GET 
Request URL: http://localhost:8000/ProjectOverview/proj_view/15/ 
Django Version:  1.3.1 
Exception Type:  ValueError 
Exception Value: incomplete format 

Exception Location:  /home/projects/bruens_erp/ProjectOverview/views.py in proj_view, line 11 

我的urls.py:

from django.conf.urls.defaults import patterns, include, url 

from django.contrib import admin 
admin.autodiscover() 

urlpatterns = patterns('', 
    url(r'^ProjectOverview/$', 'ProjectOverview.views.index'), 
    url(r'^ProjectOverview/login/$', 'ProjectOverview.views.login'), 
    url(r'^ProjectOverview/proj_view/(?P<cust>\d+)/$', 'ProjectOverview.views.proj_view'), 
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')), 
    url(r'^admin/', include(admin.site.urls)), 
) 

我的views.py:

# Create your views here. 
from django.http import HttpResponse 

def index(request): 
    return HttpResponse("Index.... please login") 

def login(request): 
    return HttpResponse("login page") 

def proj_view(request, cust): 
    return HttpResponse("project overview for cust: %." % cust) 

這段代碼有什麼問題?

回答

2

你需要讓你變得%%S(如果它是一個字符串)或%d(如果它是一個整數):

def proj_view(request, cust): 
    return HttpResponse("project overview for cust: %s." % cust) 

python string-formatting

+0

嗯是的,只是看到了錯字..該死的閱讀障礙 – jorrebor