这是我的Select *
from sys.change_tracking_databases
:
index.html
这是我的<form action="{% url 'request:my_shipment' %}" method="POST">
{% csrf_token %}
<input type="submit" value="My shipment"/>
</form>
:
urls.py
这是我的app_name = 'request'
urlpatterns = [
path('', request_views.IndexView.as_view(), name='index'),
path('create_request/', request_views.RequestView.as_view(), name="request"),
path('request/<int:pk>', request_views.UpdateReceiveView.as_view(), name='receive'),
path('my_shipment/', request_views.ListMyShipment.as_view(), name='my_shipment')
]
:
views.py
当我点击class ListMyShipment(ListView):
template_name = 'request/my_shipment.html'
def get_queryset(self):
return models.Shipment.objects.filter(shipper_id=self.request.user.id)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['user_list'] = models.User.objects.all()
context['user_id'] = self.request.user.id
return context
按钮时,这是一个回复:
My shipment
我正在使用Django 2.0.5版
答案 0 :(得分:0)
在基于Django类的视图中,你必须编写get,post,put等方法。除非你编写post函数,否则你将无法在post方法中调用该视图。
class ListMyShipment(View):
def post(self, request, **kwargs):
#your Code For post, **kwargs, request are not essential
你可以在这里了解更多关于基于类的视图的方法, class Based Views