1
我使用Django創建支付對象CreateView
然後我想將此對象的id
傳遞給另一個視圖函數,以在另一個模板上製作和顯示一些計算。我怎樣才能做到這一點?在創建對象後將ID從CreateView傳遞到另一個函數
views.py:
class CreatePayment(CreateView):
template_name = "inventory/new_payment.html"
success_url = reverse_lazy('inventory:payments_page')
model = Payments
fields = ('payment_number', 'customer','agent', 'amount')
HTML:
<body>
<form action="{% url 'inventory:new_payment'%}" method="post">
{% csrf_token %}
{{form}}
<button type="submit", value="Add">Add</button>
</form>
</body>
網址:
url(r'newpayment/$', CreatePayment.as_view(), name='new_payment')
那麼你爲什麼要取消接受我的答案嗎? –
錯誤 –
我只是想知道,希望它沒有被認爲是粗魯! –