I have a small project. There is a ready registration form in the project. I want to register on this registration form. I don't want to create inputs with python codes in forms.py. I want to record with imputs in existing HTML codes. I hope I was able to explain what I wanted. I will be glad if you help me.
register.html
{% extends 'partials/_base.html' %}
{% load static %}
{% block content %}
<!-- BREADCRUMB -->
<div id="breadcrumb">
<div >
<ul >
<li><a href="#">Home</a></li>
<li >Register</li>
</ul>
</div>
</div>
<!-- /BREADCRUMB -->
<!--REGISTER FORM-->
<div style="width: 500px;" >
<form role="form" method="post">
{% csrf_token %}
<br>
<div >
<label for="firstName" >Ad</label>
<div >
<input type="text" id="firstName" placeholder="First Name" autofocus>
</div>
</div>
<div >
<label for="firstName" >Soyad</label>
<div >
<input type="text" id="lastName" placeholder="Last Name" autofocus>
</div>
</div>
<div >
<label for="email" >Email</label>
<div >
<input type="email" id="email" placeholder="Email" >
</div>
</div>
<div >
<label for="email" >Nömrə</label>
<div >
<input type="text" id="phone" placeholder="Phone" >
</div>
</div>
<div >
<label for="password" >Şifrə</label>
<div >
<input type="password" id="password" placeholder="Password" >
</div>
</div>
<div >
<label for="birthDate" >Doğum tarixi</label>
<div >
<input type="date" id="birthDate" >
</div>
</div>
<div >
<label for="country" >Bölgə</label>
<div >
<select id="country" >
<option>Ağdam</option>
<option>Ağcabədi</option>
<option>Biləsuvar</option>
<option>Gəncə</option>
<option>Lənkaran</option>
<option>Yevlax</option>
<option>Mingəçevir</option>
<option>Goranboy</option>
</select>
</div>
</div> <!-- /.form-group -->
<div >
<div >
<div >
<label>
<input type="checkbox">I accept <a href="#">terms</a>
</label>
</div>
</div>
</div> <!-- /.form-group -->
<div >
<div >
<button type="submit" >Register</button>
</div>
</div>
</form> <!-- /form -->
</div> <!-- ./container -->
<!--/REGISTER FORM-->
<!-- section -->
<div >
<!-- container -->
<div >
<!-- row -->
<div >
</div>
<!-- /row -->
</div>
<!-- /container -->
</div>
<!-- /section -->
{% endblock %}
I didn't write model.py or views.py
CodePudding user response:
If you want to use this template for your registration form, just add name='<field_name>' for every field, because Django uses name attribute to access every field in the POST request.
Note: Make sure the name attr value and the field name are similar
It is always recommended to write forms instead of making the view to handle everything. But if you don't want to write forms, you can access each field with field_name = request.POST.get('field_name'), then pass every field to create an instance or to save to a database using this format user_obj = User.objects.create(field_name=field_name, ...)
I hope it helps :)
