0
我試圖通過ModelForm使用django.contrib.auth.models.User模型創建一個簡單的「配置文件編輯」窗體。這是我目前有:通過ModelForm編輯django.auth用戶
形式:
class UserEditForm(ModelForm):
class meta:
model = User
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super(UserEditForm, self).__init__(*args, **kwargs)
查看:
def edit_user(request, user):
user = get_object_or_404(User, username__exact = user)
form = UserEditForm(request.POST or None, request=request, instance=user)
return render_to_response('forms.html', add_csrf(request, form=form, title='Edit User'), context_instance=RequestContext(request))
邏輯上,這看起來像它應該工作,但編輯的用戶表單顯示不出來在我的模板中,當我加載頁面。我錯過了什麼?
什麼是'add_csrf'? –