Я полагаю, что есть какая-то ошибка в функции updateorder, но я не могу ее найти. Когда я нажимаю кнопку обновления на панели инструментов . html выдает ошибку, говорящую, что
Реверс для 'update_order' с аргументами '(' ',)' нет нашел. Попробован 1 шаблон (ов): ['update_order \ / (? P [^ /] +) \ / $']
views.py
from django.shortcuts import render, redirect
from django.http import HttpResponse
from accounts.models import *
from accounts.forms import OrderForm
# Create your views here.
def home(request):
customers = Customer.objects.all()
orders = Order.objects.all()
total_customers = customers.count()
total_orders = orders.count()
pending = orders.filter(status='Pending').count()
delivered = orders.filter(status='Delivered').count()
context = {'customers':customers, 'orders':orders, 'pending':pending, 'delivered':delivered, 'total_customers':total_customers,
'total_orders':total_orders}
return render(request, 'accounts/dashboard.html', context)
def products(request):
products = Product.objects.all()
return render(request, 'accounts/products.html', {'products':products})
def customer(request, pk):
customers = Customer.objects.get(id=pk)
orders = Order.objects.all()
orders_counts = orders.count()
context = {'customers':customers, 'orders':orders, 'orders_counts':orders_counts}
return render(request, 'accounts/customer.html', context)
def createorder(request):
form = OrderForm
if request.method=='POST':
form = OrderForm(request.POST)
if form.is_valid():
form.save()
return redirect('/')
context = {'form':form}
return render(request, 'accounts/order_form.html', context)
def updateorder(request, pk):
orders = Order.objects.get(id = pk)
form = OrderForm(instance = orders)
context = {'form':form}
return render(request, 'accounts/order_form.html', context)
> Blockquote
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name = 'home'),
path('products/', views.products, name = 'products'),
path('customer/<str:pk>/', views.customer, name = 'customer'),
path('create_order/', views.createorder, name = 'create_order'),
path('update_order/<str:pk>/', views.updateorder, name = 'update_order')
]
панель инструментов. html
{% extends 'accounts/main.html' %}
{% block content %}
{% include 'accounts/status.html' %}
<br>
<div class="row">
<div class="col-md-5">
<h5>CUSTOMERS:</h5>
<hr>
<div class="card card-body">
<a class="btn btn-primary btn-sm btn-block" href="">CREATE CUSTOMERS</a>
<table class = "table table-sm">
<tr>
<th>Customers</th>
<th>Phone</th>
</tr>
{% for i in customers %}
<tr>
<!-- <td><a href="{% url 'customer' i.id %}">View</a></td> -->
<td>{{i.name}}</td>
<td>{{i.phone}}</td>
<td><a class="btn btn-info" href="{% url 'customer' i.id %}">View</a></td>
</tr>
{% endfor %}
</table>
</div>
</div>
<div class="col-md-7">
<h5>LAST 5 ORDERS</h5>
<hr>
<div class="card card-body">
<a class="btn btn-primary btn-sm btn-block" href="{% url 'create_order' %}">CREATE ORDERS</a>
<table class = "table table-sm">
<tr>
<th>Product</th>
<th>Date Ordered</th>
<th>Status</th>
<th>Update</th>
<th>Remove</th>
</tr>
{% for i in orders %}
<tr>
<td>{{i.product}}</td>
<td>{{i.date_created}}</td>
<td>{{i.status}}</td>
<td><a class="btn btn-info" href="{% url 'update_order' Order.id %}">Update</a></td>
<td><a class="btn btn-danger" href="">Delete</a></td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% endblock %}
forms.py
from django.forms import ModelForm
from accounts.models import Order
class OrderForm(ModelForm):
class Meta:
model = Order
fields = '__all__'
order_forms. html
{% extends 'accounts/main.html' %}
{% load static %}
{% block content %}
<form method="post">
{% csrf_token %}
{{form}}
<input type="submit" name="Submit">
</form>
{% endblock %}