好的伙计们,我有一个自定义的用户注册表单,每当提交表单时弹出一个浏览器警告,说“127.0.0.1:8000的页面说:已提交!”没有任何反应。没有数据保存。以下是我想要保存表单的索引视图的代码:
def Index(request):
"""View to serve the index page."""
regform = models.RegistrationForm()
loginform = models.LoginForm()
if request.method == 'POST':
if 'signup' in request.POST:
form = models.RegistrationForm(request.POST)
if form.is_valid():
form.save()
message = 'Your Account has been created. You may login now.'
return shortcuts.render_to_response(
'index.html', {'message' : message, 'regform' : regform, 'loginform' : loginform})
else:
message = 'Error: Please fill in all the fields and try again'
return shortcuts.render_to_response(
'index.html', {'regform' : regform, 'message' : message, 'loginform' : loginform})
elif 'login' in request.POST:
requser = request.POST['loginemail']
reqpass = request.POST['loginpass']
'''check if email exists'''
emailexist = models.member.objects.filter(Email=requser).count()
if emailexist == 1:
exists = True
else:
exists = False
'''if email exists check for password'''
if exists == True:
mem = models.member.objects.get(Email=requser)
if reqpass == mem.Password:
request.session['member_id'] = mem.id
return shortcuts.render_to_response(
'login.html')
else:
error = 'You entered an invalid Password, Please try again.'
return shortcuts.render_to_response(
'index.html', {'error' : error, 'regform' : regform, 'loginform' : loginform})
else:
error = 'That E-mail Address is Not Registered, Please Check the spelling and try again.'
return shortcuts.render_to_response(
'index.html', {'regform' : regform, 'loginform' : loginform, 'error' : error})
else:
return shortcuts.render_to_response(
'index.html', {'regform' : regform, 'loginform' : loginform})
对不起,这是模型和注册表格的代码
型号:
class member(models.Model):
"""Model to represent a User."""
First_Name = models.CharField(max_length=100, blank=False)
Last_Name = models.CharField(max_length=100, blank=False)
Stage_Name = models.CharField(max_length=100, unique=True, blank=False)
Account_Type = models.CharField(max_length=200, choices=USERTYPE_CHOICES, blank=False)
Password = models.CharField(max_length=100, blank=False)
Email = models.EmailField(max_length=100, blank=False)
Sex = models.CharField(max_length=1, choices=GENDER_CHOICES, blank=False)
Birthday = models.CharField(max_length=2, blank=False)
def __unicode__(self):
return self.Email
报名表:
class RegistrationForm(forms.ModelForm):
Stage_Name = forms.CharField(label='Username')
Email = forms.CharField(initial='you@example.com')
Birthday = forms.CharField(initial='dd/mm/yyyy')
Password = forms.CharField(widget=forms.PasswordInput)
class Meta:
model=member
这是模板:::::
{% extends 'base.html' %}
{% load login_checkbox %}
{% block topbar %}
<head>
</head>
<body>
<div id="logo" class="left"><a href="http://www.muzikube.com/"><img src="/static/images/logo.png" alt="Muzikube" width="200" height="52" border="0"/></a></div>
<div id="login" class="right">
<form id="loginform" action="." method="post">
{% for field in loginform %}
{% if field.field.widget|is_checkbox %}
<div class="checkbox">{{field}}{{field.label_tag}}<span id="forgotpass"><a href="/forgot/">Can't Sign In?</a></span></div>
{% else %}
{{field.label_tag}}{{field}}
{% endif %}
{% endfor %}
<input id="submit" class="submit" "type="submit" name="login" value="In!" />
</form>
{% if error %}
{{error}}
{% endif %}
</div>
<div class="clear"></div>
</body>
{% endblock topbar %}
{% block content %}
<body>
<div class="left">
<div id="heading">Connect To Other Musicians</div>
<div class="subheading">Upload your music, Share Pictures, Share Videos, Make Friends, Get Known !</div>
<div id="homepageimage"><img src="/static/images/comm.png" alt="Connect to other Musicians Around the world!" width="450" height=""/></div>
<div class="subheading">Muzikube let's you connect to other people around the world that share same interests as you !</div>
</div>
<div id="registrationform" class="right">
<div id="form-title">Sign Up, It's Free !</div>
<div id="form-subtitle">Connect to other musicians around the world.</div>
<div class="border"></div>
<div class="error">
{% if message %}
{{message}}
{% endif %}
</div>
<form id="regform" action="." method="post">
<table>
{{ regform.as_table }}
</table>
<input id="register-submit" class="submit" type="submit" name="signup" value="Sign Up" />
</form>
<div class="border"></div>
</div>
<div class="clear"></div>
</body>
{% endblock content %}
答案 0 :(得分:0)
从上面的代码中说出来有点难,但我猜你会得到一个没有“登录”或“注册”的POST(我不明白为什么会有这些参数来自代码,也许它在html?) - 所以什么都没有保存或从post请求返回。