我在linux上使用django来建立一个注册网站。它不能工作!!
错误消息:视图 blog.views.register 没有返回 HttpResponse 对象。
模型.py
from django.db import models
class User(models.Model):
username = models.CharField(max_length = 20)
headImg = models.FileField(upload_to = './upload/')
def __unicode__(self):
return self.username
视图.py
class UserForm(forms.Form):
username = forms.CharField()
headImg = forms.FileField()
def register(req):
if req.method == "POST":
uf = UserForm(req.POST)
if uf.is_valid():
print uf.cleaned_data['username']
print uf.cleaned_data['headImg'].name
user = User()
user.username = uf.cleaned_data['username']
user.headImg = uf.cleaned_data['headImg']
user.save()
return HttpResponse('ok')
else:
uf = UserForm()
return render_to_response('register.html',{'uf':uf})