Wei*_* Xu 3 python django django-forms
我在做一个预填充的表单时遇到了这个奇怪的问题。在我的模板中,表单方法明确说明为POST:
<form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">{% csrf_token %}
Run Code Online (Sandbox Code Playgroud)
但在我的视图函数中, request.method 结果是GET.
下面是我的视图函数:
def editProfile(request,template_name):
theprofile = request.user.profile
print theprofile.fullname
notificationMSG = ''
print request.method
if request.method == 'POST':
form = UserProfileForm(request.POST,request.FILES, instance=theprofile)
if form.is_valid():
form.save()
notificationMSG = "success?"
else:
form = UserProfileForm()
print "error"
dic = {'form':form,
'notificationMSG':notificationMSG}
return render_to_response(template_name, dic, context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它会打印出GET. 以前有人遇到过这种奇怪的事情吗?