Ich habe ein Formular auf einer Vorlage, die jedes Mal, wenn ich die Schaltfläche "Senden" gedrückt habe, auf eine Seite umgeleitet wird, die einen Wert Fehler wirft. Ich habe versucht, online nach Hilfe zu suchen, aber hatte kein Glück, die andere Form funktioniert tadellos auf der Schablone, die es nur das Dokumentenformular ist. Ich habe online nach mehr als einem Formular auf einer Vorlage gesucht und bin dabei auf eine Art Code gestoßen, der so strukturiert ist. Aber aus irgendeinem Grund kann ich es nicht zur Arbeit bringen, ich habe versucht, eine separate Ansicht für meine zweite Form ohne Glück zu schreiben. Ich bin noch ziemlich neu im Django.Django-Wert Fehler auf mehreren Formular auf einer Seite
def modify_land(request, pk):
# Query Sets
land = get_object_or_404(Land, pk=pk)
land_use_types = LandType.objects.all()
countries = Country.objects.all()
province_states = ProvinceState.objects.all()
counties = County.objects.all()
lld_types = LLDType.objects.all()
land_owners = LandOwner.objects.all()
tenants = Tenant.objects.all()
documents = Document.objects.all()
document_types = DocumentType.objects.all()
document_statuses = DocumentStatus.objects.all()
partners = Partner.objects.all()
events = Event.objects.all()
# Forms
doc_form = DocumentForm()
# Modify Land
if request.method == "POST":
form = LandForm(request.POST, instance=land)
if form.is_valid():
land = form.save(commit=False)
land.creator = request.user
land.modified_date = timezone.now()
land.save()
messages.success(request, 'Object has Been Modified')
return redirect(lands_home)
else:
messages.error(request, 'Object Has Not Been Modified')
else:
form = LandForm(instance=land)
# Create Relationship to Document
if request.method == "POST" and 'land_rel_doc' in request.POST:
doc_form = DocumentForm(request.POST, request.FILES)
if doc_form.is_valid():
document = form.save(commit=False)
document.creator = request.user
document.created_date = timezone.now()
document.save()
messages.success(request, 'Object Has Been Created')
else:
messages.error(request, 'Object Has Not Been Created')
else:
doc_form = DocumentForm()
return render(request,
'process_lands_management/modify_land.html',
{'form': form,
'doc_form': doc_form,
'land': land,
'land_use_types': land_use_types,
'countries': countries,
'province_states': province_states,
'counties': counties,
'lld_types': lld_types,
'land_owners': land_owners,
'tenants': tenants,
'documents': documents,
'document_types': document_types,
'document_statuses': document_statuses,
'partners': partners,
'events': events,
'title': 'Modify Land'})
Fehler:
Internal Server Error: /process_lands_management/modify_land/1/
Traceback (most recent call last):
File "/home/python/.virtualenvs/django_imax/lib/python3.4/site-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/home/python/.virtualenvs/django_imax/lib/python3.4/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/home/python/.virtualenvs/django_imax/lib/python3.4/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/python/.virtualenvs/django_imax/lib/python3.4/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/python/python/django_imax/django_imax/process_lands_management/views.py", line 114, in modify_land
document = form.save(commit=False)
File "/home/python/.virtualenvs/django_imax/lib/python3.4/site-packages/django/forms/models.py", line 443, in save
'created' if self.instance._state.adding else 'changed',
ValueError: The Land could not be changed because the data didn't validate.
Willkommen bei Stackoverflow! Um bessere Antworten zu erhalten, sollten Sie angeben, was der Fehler ist und was Sie bisher versucht haben. Im Zweifelsfall sehen Sie, wie Sie eine Frage stellen können (http://stackoverflow.com/help/how-to-ask). Abschnitt – Motocarota
Danke, leider vergessen, den Fehler am Ende hinzuzufügen. – penguio