我有一个带有 POST Submit 按钮的表单。我想在提交表单和 form.is_valid() 时链接到新页面。
在视图中或模板中创建链接更好吗?怎么做?
视图.py:
from django.shortcuts import render_to_response
from ezmapping.models import *
from django.forms.models import modelformset_factory
def setName(request):
ezAppFormSet = modelformset_factory(ezApp, extra=1, fields=('name'))
formset = ezAppFormSet(queryset=ezApp.objects.none())
if request.method == 'POST':
formset = ezAppFormSet(request.POST, request.FILES)
if formset.is_valid():
formset.save()
return render_to_response("project/manage_new.html", {'formset': formset, 'title': "New"}, context_instance=RequestContext(request))
模板.html
{% extends "basemap.html" %}
{% block content %}
<table border="1">
<tr>
<td>
<h1>Define new App options</h1>
{% if formset.errors %}
<p style="color: red;">
Please correct the error{{ formset.errors|pluralize }} below.
</p>
{% endif %}
<form method="post" action="." encrypt="multipart/form-data">{% csrf_token %}
{{ formset.as_p }}
<input type="submit" value="Submit">
</form>
</td>
</tr>
</table>
{% endblock %}