当我提交表单时,它只返回带有输入的表单
在(视图.py)在from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, redirect
from quote.forms import QuoteForm
def quoting(request):
if request.method == 'GET':
form = QuoteForm()
else:
form = QuoteForm(request.POST)
if form.is_valid():
Length = form.cleaned_data['Length']
Breadth = form.cleaned_data['Breadth']
Height = form.cleaned_data['Height']
totalprice=((Length*Breadth*Height)/5000)
return render(request, "quote/quote.html", {'form': form})
def answer(request):
return render(request,"quote/out.html")
在(报价.html)在
^{pr2}$
在(输出.html)在{% extends "shop/base.html" %}
{% block content %}
{% if totalprice %}
{{ totalprice }}
{{ else }}
{{form}}
{% endblock %}
在(表单.py)在from django import forms
class ContactForm(forms.Form):
Length = forms.IntegerField(required=True)
Breadth = forms.IntegerField(required=True)
Height = forms.IntegerField()
(网址.py(应用程序)from django.conf.urls import patterns, url
from django.views.generic import TemplateView
url(r'^quoting/$',
'quote.views.quoting',
name='quoting'
),
url(r'^answer/$',
'quote.views.answer',
name='answer'
)