When i try to post data with submit button, i get nothing no reverse to (/) and no data send to the database. Normaly, i am expecting to submit data with datetimefield auto and auto add. when it finished (data sent), i will redirect the page to the previous page(/).
html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--
<title>CRM Youtube</title>
CSS only -->
<title>Groupe Utilisateurs</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<style>
#logo{
}
body{
background-color: #ebeff5;
}
#total-orders{
background-color: #4cb4c7;
}
#orders-delivered{
background-color: #7abecc;
}
#orders-pending{
background-color: #7CD1C0;
}
</style>
</head>
<body>
<!DOCTYPE html>
<!-- YouTube or Website - CodingLab -->
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!---<title>Sidebar Menu for Admin Dashboard</title>-->
<!--link rel="stylesheet" href="/static/css/stylev3adminspec.css"-->
<!-- Fontawesome CDN Link -->
<link rel="stylesheet" href="/static/css/all.min.css">
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" />-->
<!---NEW---->
<title> Tableau de bord </title>
<!-- MDB icon -->
<link rel="icon" href="img/mdb-favicon.ico" type="image/x-icon" />
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
/>
<!-- Google Fonts Roboto -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700;900&display=swap"
/>
<!-- MDB -->
<link rel="stylesheet" href="/static/css/mdb.min.css" >
<script src="https://code.jquery.com/jquery-3.7.1.slim.min.js" integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8=" crossorigin="anonymous">
</script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light font-weight-bold text-uppercase">
<!---->
<!---->
<!---->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<i class="fa fa-circle" aria-hidden="true"></i>
<a class="navbar-brand" href="/AccessAdmin/EspaceAdministrator" style="font-weight-bold" >TDB</a>
<div class="collapse navbar-collapse">
</div>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" >Ajout utilisateur </a>
</li>
</ul>
</div>
<ul class="navbar-nav d-flex flex-row">
<li class="nav-item">
<span class="nav-link">admin</span>
</li>
<li class="nav-item me-3 me-lg-0 dropdown">
<a data-mdb-dropdown-init
class="nav-link dropdown-toggle"
href="#"
id="navbarDropdown"
role="button"
aria-expanded="false"
>
<i class="fas fa-user" id="usericone"></i>
</a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="/auth/logout">Déconnexion</a>
</li>
<li><a class="dropdown-item" href="/auth/logout"><i class="fa fa-pencil fa-fw"></i> Edit</a></li>
<li><a class="dropdown-item" href="#"><i class="fa fa-trash-o fa-fw"></i> Delete</a></li>
<li><a class="dropdown-item" href="#"><i class="fa fa-ban fa-fw"></i> Ban</a></li>
<li class="divider"></li>
<li><a class="dropdown-item" href="#"><i class="fa fa-unlock"></i> Make admin</a></li>
</ul>
</li>
</ul>
</nav>
<script src="/static/js/mdb.umd.min.js"></script>
<script src="/static/src/script3adminspec.js"></script>
</body>
</html>
<br>
<form action="" method="POST">
<input type="hidden" name="csrfmiddlewaretoken" value="FZIspgaZwnt4fzOZqWnbK1RVceKTQyLbC68Nvc1F9rUygsP9Lcrymw4SEEbcwQ9x">
<div class="row">
<div class="col-md">
<div class="card card-body" >
<h5>Informations</h5>
<hr>
<br>
<fieldset>
<label for="IDF_GROUPE_USER">Nom du groupe :</label>
<!--input name="IDF_GROUPE_USER" type="text" id="IDF_GROUPE_USER" size="35"
placeholder="Nom du groupe" tabindex="1" >
-->
<select name="IDF_GROUPE_USER" id="IDF_GROUPE_USER"
tabindex="1" >*
<option value=1>prends ma main</option>
<option value=2>take way</option>
<option value=3>dffhgh</option>
<option value=4>dieu</option>
<option value=5>pour cause</option>
<option value=6>fghj</option>
<option value=7>hhkkk</option>
<option value=8>ferier</option>
<option value=9>dfgg</option>
<option value=10>derier</option>
<option value=11>fare</option>
<option value=12>fghgh</option>
<option value=13>fghgh</option>
<option value=14>prenez</option>
<option value=15>der</option>
</select>
</fieldset>
<br>
<fieldset>
<label for="user">username :</label>
<input name="user" type="text" id="user" size="35"
placeholder="User" tabindex="2" >*
</fieldset>
<br>
<fieldset>
<label for="LOGIN">LOGIN :</label>
<input name="LOGIN" type="text" id="LOGIN" size="35"
placeholder="LOGIN" tabindex="3" >*
</fieldset>
<br>
<fieldset>
<label for="name">Nom :</label>
<input name="name" type="text" id="name" size="35"
placeholder="Nom" tabindex="4" >*
</fieldset>
<br>
<fieldset>
<label for="prenom">Prenom :</label>
<input name="prenom" type="text" id="prenom" size="35"
placeholder="Prenom" tabindex="5" >*
</fieldset>
<br>
<fieldset>
<label for="MOtpasse">Password :</label>
<input name="MOtpasse" type="password" id="MOtpasse" size="35"
placeholder="Password" tabindex="6" >*
</fieldset>
<br>
<fieldset>
<label for="USERCONNECTE">Connecté ? :</label>
<select name="USERCONNECTE" id="USERCONNECTE"
tabindex="7" >*
<option value="true">Oui</option>
<option value ="false">Non</option>
</select>
</fieldset>
<br>
<fieldset>
<label for="COMPTEACTIF">Compte Actif ? :</label>
<select name="COMPTEACTIF" id="COMPTEACTIF"
tabindex="8" >*
<option value=1>Oui</option>
<option value =2>Non</option>
</select>
</fieldset>
<br>
<fieldset>
<label for="mOtpassWorkFlow"> mOtpassWorkFlow</label>
<input name="mOtpassWorkFlow" type="password" id="mOtpassWorkFlow" size="35"
placeholder="Pwd Wflow" tabindex="9" >*
</fieldset>
<br>
<fieldset>
<label for="CODeSecret"> CODeSecret</label>
<input name="CODeSecret" type="password" id="CODeSecret" size="35"
placeholder="Code Secret" tabindex="10" >*
</fieldset>
<br>
<fieldset>
<label for="EMAIL"> EMAIL</label>
<input name="EMAIL" type="email" id="EMAIL" size="35"
placeholder="EMAIL" tabindex="11" >*
</fieldset>
<br>
<fieldset>
<label for="Telephone"> Telephone </label>
<input name="Telephone" type="tel" id="Telephone" size="35"
placeholder="Telephone" tabindex="12" >*
</fieldset>
<br>
<fieldset>
<label for="Activer"> Activer ?</label>
<input name="Activer" type="checkbox" id="Activer"
value="Activer" tabindex="13" >*
</fieldset>
<br>
<fieldset>
<label for="PROFILSIGN"> PROFILSIGN</label>
<input name="Activer" type="text" id="PROFILSIGN" size="35"
placeholder="PROFIL SIGN" tabindex="14" >*
</fieldset>
<br>
<fieldset>
<label for="DATEEXPIRATION"> DATE EXPIRATION</label>
<input name="DATEEXPIRATION" type="date" id="DATEEXPIRATION" size="35"
placeholder="DATE EXPIRATION" tabindex="15" >*
</fieldset>
<br>
<fieldset>
<label for="PICTURE"> PICTURE</label>
<input name="PICTURE" type="image" id="PICTURE" size="35"
placeholder="PICTURE" tabindex="16" >*
</fieldset>
<br>
<fieldset>
<label for="DROIT"> DROIT</label>
<input name="DROIT" type="text" id="DROIT" size="35"
placeholder="DROIT" tabindex="17" >*
</fieldset>
<br>
<fieldset>
<label for="MAJ"> MAJ</label>
<input name="MAJ" type="text" id="MAJ" size="35"
placeholder="MAJ" tabindex="18" >*
</fieldset>
<br>
<fieldset>
<label for="NUMCLT"> NUMCLT</label>
<input name="NUMCLT" type="text" id="NUMCLT" size="35"
placeholder="NUMCLT" tabindex="19" >*
</fieldset>
<br>
<fieldset>
<label for="Multisite"> Multisite</label>
<select name="Multisite" id="Multisite"
tabindex="20" >*
<option value=1>Oui</option>
<option value =2>Non</option>
</select>
</fieldset>
<fieldset>
<input name="created_at" type="date" id="created_at" placeholder=""
tabindex="21" style="display:None;">
</fieldset>
<fieldset>
<input name="updated_at" type="date" id="updated_at" value="5 octobre 2024 21:02" placeholder=""
tabindex="22" style="display:None;">
</fieldset>
<fieldset>
<input name="UTIL_CREATION" type="text" id="UTIL_CREATION" value="admin" size="35"
placeholder="" tabindex="23" style="display:None;">
</fieldset>
<fieldset>
<input name="UTIL_MODIF" type="text" id="UTIL_MODIF" value="admin" size="35" placeholder=""
tabindex="24" style="display:None;">
</fieldset>
<fieldset>
<input name="Soc_sigle" type="text" id="Soc_sigle" value="ABI" size="35" placeholder=""
tabindex="25" style="display:None;">
</fieldset>
</div>
</div>
<div class="col-md">
<div class="card card-body" style="width:200px; margin-left:50%;">
<!--<h5>Client:</h5>-->
<hr>
<button class="btn btn-outline-success btn-sm btn-block" href=""
style="font-size: 10px;" type="submit" value="submit">
Valider
</button>
<button class="btn btn-outline-info btn-sm btn-block" style="font-size: 10px;" id="myButton">
Quitter
</button>
</div>
</div>
</div>
<script>
const buttons = document.getElementsByTagName("button");
var clicked = false
var b1 = document.querySelector(".b1")
var b2 = document.querySelector(".b2")
var b3 = document.querySelector(".b3")
var b5 = document.querySelector(".b5")
function hideButtons( button1, button2, button3) {
clicked = false
for (button of buttons) {
button.style.display = "inline";
}
button1.style.display = (clicked ? "inline" : "none")
button2.style.display = (clicked ? "inline" : "none")
button3.style.display = (clicked ? "inline" : "none")
clicked = !clicked
}
b1.addEventListener("click", () => {hideButtons(b2, b3, b1)})
function hideButtons1(button1, button2, button3) {
clicked = false
for (button of buttons) {
button.style.display = "none";
}
button1.style.display = "inline";
button2.style.display = "inline";
button3.style.display = "inline";
clicked = !clicked
}
b5.addEventListener("click", () => {
hideButtons1(b1, b2, b3)})
function goBack() {
window.history.back()
}
document.getElementById("myButton").addEventListener("click", function() {
window.history.back();
});
</script>
</form>
<br>
<div class="row">
<div class="col-md">
<div class="card card-body">
<table class="table table-sm">
<tr>
<th>ID</th>
<th>login</th>
<th>Prenom et Nom</th>
<th>Telephone</th>
<th>EMAIL</th>
<th>Util création</th>
<th>Date création</th>
<th>Util modification</th>
<th>Date modification</th>
</tr>
</table>
</div>
</div>
</div>
<!--https://stackoverflow.com/questions/72089986/how-to-toggle-between-button-display -->
<hr>
<h1>Footer</h1>
</body>
<!-- JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</html>
views:
def UserAjouter(request):
pk = request.user.id # l'id du user qui est entrainde faire la création
groupe = f_groupe_user.objects.get(IDF_GROUPE_USER=pk) # le groupe utilisateur du créateur du user
scuser = request.user.id
aze = "Ajout utilisateur"
sEtat = "crea" # en mode création
utilisateur = groupe.f_utilisateur_set.all() #la liste des utilisateur du même groupe créateur
groupes = f_groupe_user.objects.all() # la liste de tous les groupes
print(f"La valeur du groupe dans GroupeAjouter est : {utilisateur}")
print(f"La valeur du scuser est : {scuser}")
form=f_utilisateur_userForm()
if request.method=="POST":
#print(localize(datetime.now()))
#print(localize(datetime()))
form.created_at = datetime.now()
form.updated_at = datetime.now()
form.UTIL_CREATION = settings.WCURUSER
form.UTIL_MODIF = settings.WCURUSER
form.Soc_sigle = settings.WSOCGEN
form=f_utilisateur_userForm(request.POST)
print("Lheure locale est:")
print(localize(datetime.now()))
print(request.method)
if form.has_changed():
print("The following fields changed: %s" % ", ".join(form.changed_data))
#print(form.cleaned_data)
if form.is_valid():
#print(form.changed_data)
form.save()
return redirect('/')
else:
print("")
context = {'form':form, 'groupe': groupe, 'aze': aze, 'sEtat': sEtat, 'utilisateur': utilisateur, 'scuser': scuser,
'groupes': groupes}
return render(request, 'appMenuAdministrator/L_liste_GroupeUtilisateur/FicheCreaUser.html',context )
models:
class f_utilisateur(models.Model): # Crée un lien entre le user et les services, le 'name' étant le nom du service
IDF_UTILISATEUR=models.AutoField(primary_key=True)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
LOGIN= models.CharField(max_length=120)
name = models.CharField(max_length=120)
MOtpasse= models.CharField(max_length=120)
USERCONNECTE=models.BooleanField()
COMPTEACTIF=models.IntegerField()
prenom= models.CharField(max_length=120)
IDF_GROUPE_USER=models.ForeignKey(f_groupe_user, on_delete=models.CASCADE, null=True)
mOtpassWorkFlow=models.CharField(max_length=120, blank=True)
CODeSecret=models.CharField(max_length=120, blank=True)
EMAIL=models.CharField(max_length=120, blank=True)
Telephone = models.CharField(max_length=120, blank=True)
Activer=models.IntegerField()
PROFILSIGN=models.CharField(max_length=120, blank=True)
DATEEXPIRATION=models.DateTimeField(blank=True)
PICTURE=models.FileField(upload_to=user_directory_pathPictureUser, blank=True)
DROIT=models.IntegerField(blank=True)
MAJ=models.IntegerField()
NUMCLT=models.CharField(max_length=120)
UTIL_CREATION=models.CharField(max_length=120)
UTIL_MODIF=models.CharField(max_length=120)
Soc_sigle=models.CharField(max_length=120, blank=True)
Multisite=models.BooleanField()
created_at=models.DateTimeField(auto_now_add=True)
updated_at= models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
forms:
class f_utilisateur_userForm(forms.ModelForm):
class Meta:
model = f_utilisateur
fields = ['user', 'LOGIN', 'name', 'prenom', 'MOtpasse', 'USERCONNECTE', 'COMPTEACTIF', 'IDF_GROUPE_USER', 'mOtpassWorkFlow', 'CODeSecret', 'EMAIL', 'Telephone',
'Activer', 'PROFILSIGN', 'DATEEXPIRATION','PICTURE', 'DROIT', 'MAJ', 'NUMCLT','Multisite','UTIL_CREATION', 'UTIL_MODIF','Soc_sigle']
labels = {'user': 'username', 'LOGIN':'LOGIN', 'name':'Nom', 'prenom':'Prenom', 'MOtpasse':'Password', 'USERCONNECTE': 'CONNECTE ?', 'COMPTEACTIF':'ACTIF ?',
'IDF_GROUPE_USER': 'GROUPE', 'mOtpassWorkFlow':'Pwd WFlow', 'CODeSecret':'Code Secret', 'EMAIL':'EMAIL', 'Telephone': 'Tel.',
'Activer':'Activer', 'PROFILSIGN':'PROFIL SIGN', 'DATEEXPIRATION': 'DATE EXPIRATION','PICTURE': 'Photo', 'DROIT': 'DROIT', 'MAJ': 'MAJ',
'NUMCLT' : 'NUMCLT','Multisite': 'Multisite?', 'created_at': 'Date de création', 'updated_at': 'Date de modification',
'UTIL_CREATION': 'UTIL CREATION', 'UTIL_MODIF': 'UTIL MODIF', 'Soc_sigle':',Societe'}
widgets={
'IDF_GROUPE_USER':forms.Select(attrs={'class':'form-control'}),
}
urls:
from django.urls import path, re_path, reverse
from . import views
from .views import Registrations_Create, registrations_success
urlpatterns=[
path("Groupe_Users/add/", views.GroupeAjouter, name='GroupeAjouter'),
]
Please help to check.