I don’t think I’ve seen anything that says you’re not allowed to do this (or that your are), but is there any reason you shouldn’t? It seems to work fine.
def get_page(request, topic_slug = 'home', tag_slug = None, form = None):
#...
if form is None:
form = CommentForm()
d = {'topic':topic, 'topics':topics, 'tags':tags, 'comments':comments, 'form':form}
d.update(csrf(request))
return render_to_response('page.html', d)
def save_comment(request, topic_slug):
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
#...save
else:
kwargs = {'topic_slug':topic_slug}
kwargs['form'] =form
return get_page(request, **kwargs) #<-------------- this
return HttpResponseRedirect(reverse('get_page', kwargs = {'topic_slug':topic_slug}))
render_to_responseis just a shortcut. Result of calling it is stillHttpResponse‘s instance.As a proof, see
render_to_response()‘s declaration in source of Django:Pretty self-explanatory.
By writing this:
you actually do something like:
(but with slightly altered
kwargsargument).