私は関数を定義し、URLに2つのパラメータを渡そうとしています。URLに2つのパラメータを渡すことができません
実行すると、それは誤りここ"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') ,
]
私はURL
に合格であることを示していますhttp://127.0.0.1:8000/polls/1/2/
エラー
TypeError at /polls/1/2/
not enough arguments for format string
どのようにそれを解決するには?
ときのよう デフ詳細(要求、question_id、選択肢)と一緒に使用し、これを: "あなたが質問{}を見ていると選択肢{}"。レスポンス=フォーマット(question_id、選択) リターンはHttpResponse( "文字列フォーマット中にすべての引数が変換されない" –
申し訳ありませんが、 'format'の使用は'% 'を使用する代わりに使用されています。完全な例を示すために私の答えを更新しました。 – Tony
ありがとう、それは働いた。 –