下面是我的代码。在一些验证错误 Urls.py 之后,我不知道如何重定向回来:
(r'^comments/', include('django.contrib.comments.urls')),
视图.py:
def show_episode(request, episode) :
episode = get_object_or_404(Episode, pk=episode)
return render_to_response('episode.html', context_instance=RequestContext(request, {
'episode' : episode,
}))
情节.html:
<div class="subsection">
{% get_comment_form for episode as form %}
<table>
<form action="{% comment_form_target %}" method="post">
{% csrf_token %}
{{ form }}
<tr>
<td colspan="2" style="text-align: center">
<input type="submit" name="submit" value="Post">
<input type="submit" name="preview" value="Preview">
</td>
</tr>
<input type="hidden" name="next" value="{% url episode episode.id %}" />
</form>
</table>
</div>
<div class="subsection">{% render_comment_list for episode %}</div>
当出现一些错误时,我想回到这个表格。
我尝试,但我有一个错误:'QueryDict' 对象没有属性'_meta' 代码:
def comments(request) :
if request.method == 'POST' :
form = CommentForm(request.POST)
if (form.is_valid()) :
form.save()
return HttpResponseRedirect(request.POST['next'])
return HttpResponseRedirect('/')