Я работаю над приложением (для изучения django), в котором есть своего рода мастер-шаблон.
и view.py
@login_required
def home(request):
return render(request, '../templates/mainSection/home.html')
def createshipment(request):
if request.method == "GET":
# shipmentNumber is defined by 'SHN-000' + next Id in the shipment Table
try:
# trying to retrive the next primaryKey
nextId = Shipment.objects.all().count()
nextId += 1
except:
# if the next ID is null define the record as the first
nextId = 1
# creating the form with the shipment ID
form = CreateShipmentForm(initial={'shipmentNumber':'SHN-000' + str(nextId)})
return render(request, '../templates/mainSection/createshipment.html', {'form': form})
def saveshipment(request):
if request.method == 'POST':
form = CreateShipmentForm(request.POST)
if form.is_valid():
try:
form.save()
except (MultiValueDictKeyError, KeyError) as exc:
return HttpResponse('Missing POST parameters {}'.format(exc), status=400)
else:
messages.error(request, form.errors)
return render(request, '../templates/mainSection/fillshipment.html')
def viewshipment(request):
return render(request, '../templates/mainSection/viewshipment.html')
def fillshipment(request):
if request.method == "GET":
# creating the form
productForm = CreateProductForm()
# Retrieving The Product types for the ShipmentForm
productType_list = ProductTypes.objects.all()
shipment_list = Shipment.objects.all()
return render(request, '../templates/mainSection/fillshipment.html', {'productTypes': productType_list, 'shipments': shipment_list, 'productForm': productForm})
и urls.py
urlpatterns = [
path('home/', views.home,name="home"),
path('home/createshipment/',views.createshipment,name="createshipment"),
path('home/createshipment/saveshipment/',views.saveshipment,name="saveshipment"),
path('home/fillshipment/',views.fillshipment,name="fillshipment"),
path('home/viewhipment/',views.viewshipment,name="viewshipment"),
]
Проблема, которую я пытаюсь решить, заключается в следующем:
После отправки формы и перехода к следующей шаблон отличается от предыдущего URL.Например, после создания отгрузки (дом / создание /) я хочу перейти к заполнению отгрузки (дом / заполнение /).Html рендерит нормально под неправильным URL (home / creationhipment / saveshipment /)
Что я делаю не так?