我在单个页面中有两个html模块用于注册,另一个用于登录。但是我找不到一种方法将这些数据保存在django数据库中。我是django的新手,所以我不知道如何将html文件与django关联起来。我把它作为头版连接起来,但就后端而言,我完全迷失了。我需要从头开始的帮助。这里是我的html文件。提前致谢。如何在django中保存html表单的数据
<body>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#about">About Us</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
<h1 style="color: white; text-align: center; padding: 260px 0px 0px 30px;">getTogether</h1>
<h3 style="color: white; text-align: center;">A place to socialize and make friends</h3>
<button onclick="document.getElementById('id01').style.display='block'" class="button button1">Sign Up</button>
<div id="id01" class="w3-modal w3-animate-opacity">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
<form class="modal-content animate" action="/home/user_profile" method="post">
{% csrf_token %}
<div class="container">
<label><b>Name</b></label>
<input type="text" placeholder="Enter Your Name" name="email" required>
<label><b>Email</b></label>
<input type="email" placeholder="Enter Email" name="email" required>
<label><b>Contact Number</b></label>
<input type="text" name="Phone Number" pattern="[7-9]{1}[0-9]{9}" placeholder="Enter Your Contact Number" name="email" required>
<label><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<label><b>Repeat Password</b></label>
<input type="password" placeholder="Repeat Password" name="psw-repeat" required>
<input type="checkbox" checked="checked"> Remember me
<p>By creating an account you agree to our <a href="#">Terms & Privacy</a>.</p>
<div class="clearfix">
<button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button>
<a href="{% url 'user_profileview' %}"><button type="submit" class="signupbtn">Sign Up</button></a>
</div>
</div>
</form>
</div>
<script>
// Get the modal
var modal = document.getElementById('id01');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
<button onclick="document.getElementById('id02').style.display='block'" class="button button1">Sign In</button>
<div id="id02" class="w3-modal w3-animate-opacity">
<span onclick="document.getElementById('id02').style.display='none'" class="close" title="Close Modal">×</span>
<form class="modal-content1 animate" action="/home/user_profile" method="post">
{% csrf_token %}
<div class="container">
<label><b>Name</b></label>
<input type="text" placeholder="Enter Your Name" name="email" required>
<label><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<div class="clearfix">
<button type="button" onclick="document.getElementById('id02').style.display='none'" class="cancelbtn1">Cancel</button>
<a href="{% url 'user_profileview' %}"><button type="submit" class="signupbtn1">Sign In</button></a>
</div>
</div>
</form>
</div>
<script>
// Get the modal
var modal = document.getElementById('id02');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
嗨,对于登录你应该有一个网址和注册你应该另一个URL例如=>登录网址是'/登录'和注册网址是'/注册'。在urls.py中找到这两个网址,然后在动作 – hadi