0
我創建了一個HTML表單,試圖做簡單的註冊。提交表單後數據沒有出現在數據庫中
問題是,單擊提交按鈕後沒有錯誤出現,但當我chech數據庫字段中的數據不存在。
signup.html
<form action="\polls\Registration" method="POST">
<div class="form-group mb15">
<input type="text" class="form-control" name="userName" placeholder="Enter Your Username" required>
</div>
<div class="form-group mb15">
<input type="password" class="form-control" name="password" placeholder="Enter Your Password">
</div>
<div class="form-group mb15">
<input type="text" class="form-control" name="fullName" placeholder="Enter Your Full Name">
</div>
<div class="form-group mb20">
<label class="ckbox">
<input type="checkbox" name="checkbox">
<span>Accept terms and conditions</span>
</label>
</div>
<div class="form-group">
<button class="btn btn-success btn-quirk btn-block">Create Account</button>
<br>
<a href="/polls/signin" class="btn btn-default btn-quirk btn-stroke btn-stroke-thin btn-block btn-sign">Already a member? Sign In Now!</a>
</div>
</form>
forms.py
class RegistrationForm(forms.Form):
userName= forms.CharField(label='Username',max_length=100)
password = forms.CharField(label='Password', max_length=100)
fullName= forms.CharField(label='Full Name', max_length=100)
myview.py
def reg(request):
if request.method == 'POST':
the request:
form = forms.RegistrationForm(request.POST)
if form.is_valid():
return HttpResponseRedirect('/polls/signin')
else:
form = forms.RegistrationForm()
return render(request, 'signup.html', {'form': form})
urls.py
urlpatterns = [
url(r'^Registration', myview.reg,name='Registration'),
]
你認爲你在做什麼將數據寫入數據庫? –
我想數據提交應該在myview.py.But我認爲這是不可能的,因爲沒有代碼做that.maybe我應該在模型中完成insteadOk是新的django和python.any提示如何請做 – Colo
我不明白你的評論。什麼是不可能的?你有接受來自表單的數據的代碼;現在你實際上必須用這些數據做一些事情。 –