简体   繁体   中英

Getting ValueError as response to http request in Django framework

When i access this url:

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

Django tells me that the format is in complete:

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

My 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)),
)

My 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)

What is wrong with this code?

You need to make your % become %s (if it's an string) or %d (if it's an integer):

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

See python string-formatting .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM