django ModelFormを使用してサインアップページを作成しています。 models.pydjangoのModelFormを使用してサインアップページから値を取得
from django.db import models
from django.forms import ModelForm
country_choices=(
('india','INDIA'),
('egypt','EGYPT'),
('germany','GERMANY'),
('afghanistan','AFGHANISTAN'),
('switzerland','SWITZERLAND'),
('usa','USA'),
('mexico','MEXICO'),
)
class user(models.Model):
uid=models.IntegerField(unique=True,default=0)
uname=models.CharField(max_length=50)
email=models.EmailField()
password=models.CharField(max_length=20)
phoneno=models.IntegerField(default=0)
addr1=models.CharField(max_length=50)
addr2=models.CharField(max_length=50)
city=models.CharField(max_length=20)
state=models.CharField(max_length=20)
country=models.CharField(max_length=20,choices=country_choices)
pincode=models.IntegerField(default=0)
securityq=models.CharField(max_length=100)
securitya=models.CharField(max_length=100)
def __unicode__(self):
return self.uid,self.uname
class Meta:
db_table="user"
class userForm(ModelForm):
class Meta:
model= user
fields= ['uid','uname','email','password','phoneno','addr1','addr2','city','state','country','pincode','securityq','securitya']
views.py
from django.shortcuts import render
from django.http import HttpResponseRedirect
from .models import userForm
def homepage(request):
return render(request,'student/homepage.html',)
def signuppage(request):
return render(request,'student/signuppage.html',)
def get_userdetails(request):
if request.method=='POST':
form=userForm(request.POST)
if form.is_valid():
new_form=form.save()
return HttpResponseRedirect('student/signuppage.html')
else:
form=userForm()
return render(request,'student/homepage.html',{'form':form})
signuppage.html
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<title>Sign Up</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="{% static 'student/signupcss.css' %}" />
</head>
<body>
<div class="container">
<section id="content">
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<h1>Create an Account</h1>
{{form}}
<input type="submit" value="Submit" />
</form>
</section>
</div>
</body>
</html>
しかし、それだけで "アカウントを作成" と "送信" ボタンを空白のフォームを表示します/student/signuppage.htmlにアクセスすると...テキストボックスやドロップダウンはありません...自動的に生成されるはずですか?
また、私はModelformsを使ってforms.pyを作成する必要がありますか...もしそうなら、その中に何を入れますか?
があることでした...まだ何もありません。 – Shefali