Reputation: 9
This is my index.html
:
<form action="{% url 'request:my_shipment' %}" method="POST">
{% csrf_token %}
<input type="submit" value="My shipment"/>
</form>
This is my 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')
]
This is my 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
And this is a respond when I click to My shipment
button:
Method Not Allowed (POST): /my_shipment/
I am using Django version 2.0.5
Upvotes: 0
Views: 1465
Reputation: 97
In Django class based view you have to write methods like get, post, put etc.. unless you write post functions you will not be able to call that view in post method.
class ListMyShipment(View):
def post(self, request, **kwargs):
#your Code For post, **kwargs, request are not essential
you can learn more about class based views post method here, class Based Views
Upvotes: 1