【发布时间】:2017-11-11 21:24:04
【问题描述】:
我定义了一个函数,并试图在 URL 中传递两个参数。
运行时显示错误"not enough arguments for format string"
这里是代码 views.py
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
def detail(request, question_id,choice):
response="You're looking at question %s and choice %s."
return HttpResponse(response % question_id , choice)
urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url( r'^$', views.index , name='index' ) ,
url( r'^(?P<question_id>[0-9])/(?P<choice>[0-9]+)/$', views.detail , name='detail' ) ,
]
当我传递网址时
http://127.0.0.1:8000/polls/1/2/
错误
TypeError at /polls/1/2/
not enough arguments for format string
如何解决?
【问题讨论】: