4つの引数を持つ関数を定義しようとしていますが、私の第4引数で問題に直面しています。ここに私のコードです:django python:欠落している1つの位置指定引数
views.py:ここ
def create_recording(request, slug, inspection_id, component_id):
inspection = get_object_or_404(Inspection, pk=inspection_id)
plant = get_object_or_404(Plant, slug=slug)
component=get_object_or_404(Component, pk=component_id)
if request.method == "POST":
form = RecordingForm(request.POST)
if form.is_valid():
recording = form.save(commit=False)
recording.plant = plant
recording.inspection=inspection
recording.component=component
recording.save()
return redirect('data:inspection_detail', slug=plant.slug, inspection_id=inspection.id)
else:
form = RecordingForm()
context = {'form': form, 'plant':plant,'inspection':inspection}
template = 'data/create_recording.html'
return render(request, template, context)
は私のhtmlファイルです:
<a href="{% url 'data:create_recording' slug=plant.slug inspection_id=inspection.id component_id=1 %}">
<button type="button" class="btn btn-success">
<span class="glyphicon glyphicon-plus"></span> Chaiir
</button>
</a>
<a href="{% url 'data:create_recording' slug=plant.slug inspection_id=inspection.id component_id=2 %}">
<button type="button" class="btn btn-success">
<span class="glyphicon glyphicon-plus"></span> Table
</button>
</a>
URL:
url(r'^plants/(?P<slug>[-\w]+)/inspection(?P<inspection_id>[0-9]+)/create_recording$', views.create_recording, name='create_recording'),
と私は次のエラーを取得する:
Exception Type: TypeError
Exception Value:create_recording() missing 1 required positional argument: 'component_id'
HTMLテンプレートがcreate_recording 'にキーワードスタイルの引数を渡す()':
EDITは: あなたのURLで問題があります。おそらくどちらか一方を変更して、どちらも同じスタイルを使用する必要があります。 –
id = 1の問題は何ですか? id = 1を渡すと、どのようなエラーが表示されますか? – Exprator