2016-11-17 14 views
-1

私はちょうどPython/Djangoで書かれたプロジェクト管理ソフトウェアの開発を引き継いでいます...Python/Django-一つのHTMLページから別のHTMLページにボタンをコピーする

ウェブページの1つに表示されるボタンがいくつかあり、アプリケーション内の別のページに表示すると便利です。私は、これらのボタンは、次のコードでbudget.htmlで定義されていることがわかります。

{% block page_options %} 
    <a class="button m-r-md" href="{% url 'costing:export_csv' budget.id %}">Export to Excel</a> 
    <a class="button m-r-md" href="{% url 'costing:schedule_of_works_post_dep' budget.id %}" target="_blank">Schedule of works</a> 
    <a class="button m-r-md" href="?pdf=1" target="_blank">PDF</a> 
    <input data-view-url="{% url 'costing:combined_budget' project.id %}?search=" type="text" id="item_search" placeholder="Item search" /> 
{% endblock page_options %} 

私はthem- variations.htmlを使用できるようにする他のページには、その{%block page_options %}ブロックで、既に次のコードを持っています

{% block page_options %} 
    <button class="button modalBtn" name="variation">+ Add variation</button> 

    <a class="button" href="{% url 'costing:add_omit_builder' project.id %}">+ Add group</a> 

    <a class="button" id="scas" data-view-url="{% url 'costing:preview_scas' project.budget_overview.version.id %}" href="{% url 'costing:scas_2_variations' project.budget_overview.version.id %}">+ Standard cost assumptions</a> 

    <!--ERF(17/11/2016 @ 1700) Add buttons to export adds/ omits table to excel --> 


{% endblock page_options %} 

だから私はコピーを試してみましたが、2ページ目には、このブロックに最初のページからのコードを貼り付け:

{% block page_options %} 
    <button class="button modalBtn" name="variation">+ Add variation</button> 

    <a class="button" href="{% url 'costing:add_omit_builder' project.id %}">+ Add group</a> 

    <a class="button" id="scas" data-view-url="{% url 'costing:preview_scas' project.budget_overview.version.id %}" href="{% url 'costing:scas_2_variations' project.budget_overview.version.id %}">+ Standard cost assumptions</a> 

    <!--ERF(17/11/2016 @ 1700) Add buttons to export adds/ omits table to excel --> 
     <a class="button m-r-md" href="{% url 'costing:export_csv' budget.id %}">Export to Excel</a> 
<a class="button m-r-md" href="{% url 'costing:schedule_of_works_post_dep' budget.id %}" target="_blank">Schedule of works</a> 
<a class="button m-r-md" href="?pdf=1" target="_blank">PDF</a> 
<input data-view-url="{% url 'costing:combined_budget' project.id %}?search=" type="text" id="item_search" placeholder="Item search" /> 


{% endblock page_options %} 

が、私は今のviをしようとすると、ユーイングブラウザでこのページには、私が言うエラーページを取得:私は、私はこのエラーを取得しています理由はわからないんだけど、コスト計算/ 5915 /バリエーション/時

NoReverseMatch/

を.. 。私はHTMLファイルのどこかでコピーしたコードで、私が使っているビューの呼び出しを参照する必要がありますか?両方のHTMLファイルは同じアプリに入っていますので、同じmodels.pyファイルを共有していますので、両方ともこのアプリで定義されているmodels & viewsのすべてを使用できると思っていましたか?

これが該当しますか?その場合、バリエーションページでこのエラーが発生するのはなぜですか?

+1

。 –

+0

しかし、本当の助けが必要な場合は、*完全なエラーとトレースバックを投稿する必要があります。 –

答えて

0

あなたが言ったことに基づいて、私はあなたがコンテキスト変数の "予算"値を持っていないということが問題だと思います。最初のテンプレートを使っているという見方は、文脈上「予算」を送ると思います。 しかし、2番目のビューではありません。つまり、2番目のテンプレートでbudget.idを取得しようとすると、エラーが発生します。

ビュー内のコンテキストを修正し、「予算」変数を追加してみます。

def my_view(request, pk): 
    budget= get_object_or_404(Budget, pk=pk) 
    return render(request, 'budget.html', {'budget': budget}) 

それとも、クラスベースのビューを使用している場合は、get_context_dataメソッドをオーバーライドする必要があります:あなたはコピーして貼り付けコードしている場合、あなたはすでに何か間違ったことをやっている

def get_context_data(self, **kwargs): 
    context = super().get_context_data(**kwargs) 
    context['budget'] = self.budget 
    return context 
関連する問題