Ich habe ein Formular, das einen Wert als Eingabe nimmt, und ich verarbeite die Eingabe und die erforderliche Ausgabe zurück. Als ich nun versuchte, die Ausgabe anzuzeigen, wurde sie nicht auf der Webseite angezeigt. Django - Template-Tags funktionieren nicht richtig nach Formularvalidierung
Das folgende ist mein forms.py:
class CompForm(forms.ModelForm):
class Meta:
model = Comp
fields = ('inp',)
Die folgende meine views.py ist:
def index(request):
form = CompForm(request.POST or None)
context = {
'form': form,
}
print context
if form.is_valid():
...
...
outData = "The values you gave is correct"
errData = "The values you gave is incorrect"
print context
context['outData'] = outData
context['errData'] = errData
print context
return render(request, 'comp/index.html', context)
Das folgende ist mein index.html:
{% extends "comp/base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="row">
<div class="col-md-8 col-md-offset-2">
<form method="post" action="">
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-primary" type="submit" name="Submit" />
</form>
</div>
</div>
{% if outData %}
{{ outData.as_p }}
{% endif %}
{% if errData %}
{{ errData.as_p }}
{% endif %}
{% endblock %}
In das Terminal Ich bin in der Lage, die outData
und errData
im Wörterbuch zu bekommen, aber es wird nicht angezeigt in der Webseite. Was könnte der Fehler sein? Freundlich helfen.
'outData' und' errData' sind nur Zeichenfolgen, warum rufen Sie '.as_p' auf ihnen? '.as_p' sollte auf Formen –
@ TimmyO'Mahony aufgerufen werden Vielen Dank .. Ich weiß nicht, dass ... Jetzt hat es funktioniert ... Danke ... – Jeril
Ich werde es als Antwort hinzufügen –