view代碼:
user = request.user
initial={}
if user.is_authenticated():
initial={'name': user.username, 'email': user.email}
form = comments.get_form()(photo, initial=initial)
if user.is_authenticated():
form.fields['name'].widget.attrs['disabled'] = 'disabled'
form.fields['email'].widget.attrs['disabled'] = 'disabled'
#form.fields['email'].widget.attrs['readonly'] = True
form.fields['email'].widget.attrs['size'] = 50
form.fields['name'].widget.attrs['size'] = 50
form.fields['email'].label = 'e-Mail'
#form.fields['designation'].widget = widgets.HiddenInput()
form.fields['url'].widget = widgets.HiddenInput()
form.fields['honeypot'].widget = widgets.HiddenInput()
return render_to_response('./photomanager/photo.html', {'filename':filename, 'index':index, 'photo':photo, 'form':form}, context_instance=RequestContext(request))
template 代碼
<div id="comment_form">
<form action="#comments" class="comments" method="post">
{{ form.as_p }}
<input type="submit" value="Submit Comment">
</form>
</div>
倒序
{% get_comment_list for event as comment_list %}
{% for comment in comment_list reversed %}
...
{% endfor %}