django "put method" specify in html but still get send when button submit

html file:

<div class="row">
	<div class="col-md">
		<div class="card card-body">
			<form action="" method="POST" enctype="multipart/form-data">
            {% csrf_token %}
				<h5>Informations</h5>
				<hr>
				<p>Nom: </p>
				<fieldset>
					<input name="LibELE_GROUPE"  type="text"  id="LibELE_GROUPE" value={{LibELE_GROUPE}} size="35" placeholder="Nom du groupe" tabindex="1" required>*
                </fieldset>
				<fieldset>
					<input name="created_at"  type="text"  id="created_at" value={{created_at}} size="35" placeholder="" tabindex="2"  style="display:None;">
                </fieldset>
				<fieldset>
					<input name="updated_at"  type="text"  id="updated_at" value={{updated_at}} size="35" placeholder="" tabindex="3" style="display:None;">
                </fieldset>
				<fieldset>
					<input name="UTIL_CREATION"  type="text"  id="UTIL_CREATION" value={{UTIL_CREATION}}  size="35" placeholder="" tabindex="4" style="display:None;">
                </fieldset>
				<fieldset>
					<input name="UTIL_MODIF"  type="text"  id="UTIL_MODIF" value={{UTIL_MODIF}} size="35" placeholder="" tabindex="5" style="display:None;">
                </fieldset>
				<fieldset>
					<input name="Soc_sigle"  type="text"  id="Soc_sigle" value={{Soc_sigle}} size="35" placeholder="" tabindex="6" style="display:None;">
                </fieldset>
			</form>
		</div>
	</div>

	<div class="col-md">
		<div class="card card-body" style="width:200px; margin-left:70%;">
			<!--<h5>Client:</h5>-->
			<hr>
			<input class="b4 btn-outline-success  btn-sm btn-block" type="submit" value="Submit" style="font-size: 10px; " >
		</div>
	</div>

</div>


<br>
<div class="row">
	<div class="col">
		<div class="card card-body">
			<form method="get">

		    <button class="btn btn-primary" type="submit">Search</button>
		  </form>
		</div>
	</div>

</div>
<br>

<div class="row">
	<div class="col-md">
		<div class="card card-body">
			<table class="table table-sm">
				<tr>
					<th>Produit</th>
					<th>Categorie</th>
					<th>Date de Commande</th>
					<th>Status</th>
					<th>Mise à Jour</th>
					<th>Supprimer</th>
				</tr>

			</table>
		</div>
	</div>
</div>
<!--https://stackoverflow.com/questions/72089986/how-to-toggle-between-button-display -->
<script>

</script>
{% endblock content%}

Views file:

def groupAddok(request):
    if request.method == 'POST':
        print('Je rentre dans group addok')
        sEtat="modif"
        created_at = localize(
            datetime.now()) 
        updated_at = localize(datetime.now())
        UTIL_CREATION = settings.WCURUSER
        UTIL_MODIF = settings.WCURUSER
        Soc_sigle = settings.WSOCGEN
        LibELE_GROUPE ='Traiter'
       
        form = f_groupe_userForm(request.POST)
        print(request.method)

        if form.has_changed():
            print("The following fields changed: %s" % ", ".join(form.changed_data))
        #form.changed_data

        if form.is_valid():
            print(form.cleaned_data)

            if LibELE_GROUPE is not None :
                print('Libelle saisi')
                f_groupe_user = f_groupe_user(LibELE_GROUPE = LibELE_GROUPE, created_at = created_at, updated_at = updated_at, UTIL_CREATION = UTIL_CREATION, UTIL_MODIF = UTIL_MODIF, Soc_sigle = Soc_sigle)
                print('la valeur du groupe est ')
                print('f_groupe_user')
                if 'Ajouter' in request.POST:
                    print('Oui on peut ajouter')
                    f_groupe_user.save()
                    print('ajout effectué!!!')
                    return HttpResponseRedirect("CreateGroup/success")
                else:
                    return HttpResponseRedirect("CreateGroup")

            else:

                return HttpResponse("Vous devriez vous assurer que tous les champs sont renseignés et validés!")
        else:
            print('form pas valide')
            return render(request, 'appMenuAdministrator/list_groupes.html', {'form': form})
    else:
        print('La valeur de la methode est avec la form est invalide -- ')
        print(request.method)
        form = f_groupe_userForm()
        return render(request, 'appMenuAdministrator/list_groupes.html', {'form': form})

forms file:

class f_groupe_userForm(forms.ModelForm):
    class Meta:
        model = f_groupe_user
        fields = ['LibELE_GROUPE',  'UTIL_CREATION', 'UTIL_MODIF']
        labels = {'LibELE_GROUPE': 'Nom*', 'created_at': 'Date de création',  'updated_at': 'Date de modification', 'UTIL_CREATION': 'UTIL CREATION', 'UTIL_MODIF': 'UTIL MODIF'}
        #exclude = ["Soc_sigle"]
        widgets={
            'name'           : forms.TextInput(attrs={'class':'form-control'}),
        }
        help_texts = {
            "LibELE_GROUPE": _("Donner le nom du groupe utilisateur"),
        }
        error_messages = {
            "name": {
                "max_length": _("Ce nom du groupe est trop long."),
            },
        }

models file:

class f_groupe_user(models.Model):
    IDF_GROUPE_USER=models.AutoField(primary_key=True)
    LibELE_GROUPE= models.CharField(max_length=120)
    Soc_sigle = models.CharField(max_length=120, editable=False)
    created_at=models.DateTimeField(auto_now_add=True)
    updated_at= models.DateTimeField(auto_now=True)
    UTIL_CREATION= models.CharField(max_length=120)
    UTIL_MODIF= models.CharField(max_length=120)

urls file:

path("groupAddok", views.groupAddok, name="groupAddok"),

But not put when submit button:

[03/Oct/2024 23:27:08] "GET /AccessAdmin/EspaceAdministrator HTTP/1.1" 200 6704
[03/Oct/2024 23:27:08] "GET /static/css/all.min.css HTTP/1.1" 404 1985
La valeur de la methode est avec la form est invalide -- 
GET
[03/Oct/2024 23:27:15] "GET /AccessAdmin/groupAddok HTTP/1.1" 200 6994
[03/Oct/2024 23:27:15] "GET /static/css/all.min.css HTTP/1.1" 404 1985

Please help to fix

Side Note: When posting code here, enclose the code between lines of three
backtick - ` characters. This means you’ll have a line of ```, then your code,
then another line of ```. This forces the forum software to keep your code
properly formatted. (I have taken the liberty of correcting your original posts.
Please remember to do this in the future.)

Thank you a lot for that. Please i am waiting for your help.

How are you navigating to that page? Is there a link that you’re clicking on in the AccessAdmin/EspaceAdministrator page?

Please here is where i click on for the link. I am trying to format the code as you adviced. thanks.

Here is my full html file using:

<div class="row">
	<div class="col-md">
		<div class="card card-body">
			<form action="" method="POST" enctype="multipart/form-data">
            {% csrf_token %}
				<h5>Informations</h5>
				<hr>
				<p>Nom: </p>
				<fieldset>
					<input name="LibELE_GROUPE"  type="text"  id="LibELE_GROUPE" value={{LibELE_GROUPE}} size="35" placeholder="Nom du groupe" tabindex="1" required>*
                </fieldset>
				<fieldset>
					<input name="created_at"  type="text"  id="created_at" value={{created_at}} size="35" placeholder="" tabindex="2"  style="display:None;">
                </fieldset>
				<fieldset>
					<input name="updated_at"  type="text"  id="updated_at" value={{updated_at}} size="35" placeholder="" tabindex="3" style="display:None;">
                </fieldset>
				<fieldset>
					<input name="UTIL_CREATION"  type="text"  id="UTIL_CREATION" value={{UTIL_CREATION}}  size="35" placeholder="" tabindex="4" style="display:None;">
                </fieldset>
				<fieldset>
					<input name="UTIL_MODIF"  type="text"  id="UTIL_MODIF" value={{UTIL_MODIF}} size="35" placeholder="" tabindex="5" style="display:None;">
                </fieldset>
				<fieldset>
					<input name="Soc_sigle"  type="text"  id="Soc_sigle" value={{Soc_sigle}} size="35" placeholder="" tabindex="6" style="display:None;">
                </fieldset>
			</form>
		</div>
	</div>

	<div class="col-md">
		<div class="card card-body" style="width:200px; margin-left:70%;">
			<!--<h5>Client:</h5>-->
			<hr>

			{% if sEtat == "crea" %}
			<a class="btn btn-outline-success  btn-sm btn-block" href="" style="font-size: 10px; " >Ajouter</a>
			<a class="btn btn-outline-info  btn-sm btn-block" href="" style="font-size: 10px;" >Quitter</a>
			{% elif sEtat == "modif" %}
			<button class="b3  btn-outline-warning  btn-sm btn-block " href="" style="font-size: 10px;display:None;" >Modifier</button>
			<button class="b2  btn-outline-danger  btn-sm btn-block " href="" style="font-size: 10px; display:None;" >Supprimer</button>
			<button class="b1  btn-outline-secondary  btn-sm btn-block " href="" style="font-size: 10px; display:None;" >Annuler</button>
			<button class="b4 btn-outline-success  btn-sm btn-block"  name="Ajouter" type="submit" value="Submit" style="font-size: 10px; " >Ajouter</button>
			<button class="b5 btn-outline-info  btn-sm btn-block" href="" style="font-size: 10px; " >Quitter</button>
			{% else %}
			<a class="btn btn-outline-success  btn-sm btn-block" href="" style="font-size: 10px; ">Ajouter</a>
			<a class="btn btn-outline-info  btn-sm btn-block" href="" style="font-size: 10px;">Quitter</a>
			{% endif %}

		</div>
	</div>

</div>Preformatted text
<br>
<div class="row">
	<div class="col">
		<div class="card card-body">
			<form method="get">
		    <button class="btn btn-primary" type="submit">Search</button>
		  </form>
		</div>
	</div>

</div>
<br>
<div class="row">
	<div class="col-md">
		<div class="card card-body">
			<table class="table table-sm">
				<tr>
					<th>Produit</th>
					<th>Categorie</th>
					<th>Date de Commande</th>
					<th>Status</th>
					<th>Mise à Jour</th>
					<th>Supprimer</th>
				</tr>

			</table>
		</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)})
</script>
{% endblock content%}

I have a difficult to format the code here but i am still trying.

Again, you need to surround code that you post between lines of ```.

The ``` must be lines by themselves and not part of any other line.

The view you show here is the view that sends you to /AccessAdmin/EspaceAdministrator. I’m looking for that view, and the template for that page that is sending you to /AccessAdmin/groupAddok.

def login_blog(request):
    if request.method=="POST":
        form=LoginForm(request.POST)
        adminok = 'nok'
        if form.is_valid():
            username = form.cleaned_data['username']
            pwd      = form.cleaned_data['pwd']

            user=authenticate(username=username, password=pwd)
            if user is not None:
                if username == 'admin':
                    adminok = 'ok'
                    settings.WCURUSER='admin'
                    print("La valeur de settings.WCURUSER est ")
                    print(settings.WCURUSER)
                    login(request, user)
                    #return render(request, 'appMenuAdministrator/dbAdministrator.html', {'adminok': adminok})
                    #return render(request, 'appMenuAdministrator/StyleAppv3.html', {'adminok': adminok})
                    return redirect("/AccessAdmin/EspaceAdministrator")

                else:
                    login(request,user)
                    return redirect('dashboard')
            else:
                messages.error(request, "Authentificaion échouée")
                return render(request, 'login.html', {'form':form})
        else:
            #messages.error(request, "Authentificaion échouée")
            for field in form.errors:
                form[field].field.widget.attrs['class'] += ' is-invalid'
            return render(request, 'login.html', {'form': form})
    else:
        form = LoginForm()
        return render(request, "login.html", {"form":form})
def home(request):
    return render(request, "appMenuAdministrator/StyleAppv3.html")

<!DOCTYPE html>
{% load static %}
<!-- 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/stylev3.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>{% block title %} Tableau de bord {% endblock %}</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>
 <!--
 {% if adminok == 'ok' %}
 href="{% url 'EspaceAdministrator' %}"
 {% endif %}
 -->
 <body>
   <nav class="sidebar">

     <a href="#" class="logo">CodingLab</a>

     <div class="menu-content">
       <ul class="menu-items">
         <div class="menu-title">Your menu title</div>

         <li class="item">
           <a href="#">Your first link</a>
         </li>

         <li class="item">
           <div class="submenu-item">
             <span>User Groupware</span>
             <i class="fa-solid fa-chevron-right"></i>
           </div>

           <ul class="menu-items submenu">
             <div class="menu-title">
               <i class="fa-solid fa-chevron-left"></i>
               Configuration
             </div>
             <li class="item">
               <a href="{% url 'groupAddok' %}">Groupe</a>
             </li>
             <li class="item">
               <a href="{% url 'CreateGroup' %}">Groupe1</a>
             </li>
             <li class="item">
               <a href="#">Utilisateur</a>
             </li>
             <li class="item">
               <a href="#">Config Groupe Utilisateur</a>
             </li>
           </ul>
         </li>
         <li class="item">
           <div class="submenu-item">
             <span>Paramètre de Gestion</span>
             <!--<span>Second submenu</span>-->
             <i class="fa-solid fa-chevron-right"></i>
           </div>

           <ul class="menu-items submenu">
             <div class="menu-title">
               <i class="fa-solid fa-chevron-left"></i>
               Configurer
             </div>
             <li class="item">
               <a href="{% url 'addverif' %}">Inscription</a>
             </li>
             <li class="item">
               <a href="{% url 'register' %}">Créer un compte</a>
             </li>
             <li class="item">
               <a href="#">Second sublink</a>
             </li>
             <li class="item">
               <a href="#">Second sublink</a>
             </li>
         
           </ul>
         </li>

         <li class="item">
           <a href="#">Your second link</a>
         </li>

         <li class="item">
           <a href="#">Your third link</a>
         </li>
       </ul>
     </div>
   </nav>

   <nav class="navbar">

     <i class="fa-solid fa-bars" id="sidebar-close"></i>
     <ul class="navbar-nav d-flex flex-row" style="font-size: 15px;">
       {% if user.is_authenticated%}
       <li class="nav-item">
         <span class="nav-link">{{user.username}}</span>
       </li>
       {% endif %}

       <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>
             {% if user.is_authenticated%}
             <a class="dropdown-item" href="{% url 'logout-blog' %}">Déconnexion</a>
             {% endif %}
           </li>
           <li><a class="dropdown-item" href="{% url 'logout-blog' %}"><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>


   <main class="main">
     <h1>Admin Dashboard Content</h1>
   </main>

   <script src="{% static 'js/mdb.umd.min.js' %}"></script>
   <script src="{% static 'src/script3.js' %}"></script>
 </body>
</html>

You have the view and templates. Thanks.

What view? What template?

You need to provide more details here of what I’m looking at and not just post the code.

You still haven’t explained how you are navigating to that page. What are you clicking on that is sending you to /AccessAdmin/groupAddok?
Whatever that is, it’s that that is causing the GET, not the form on that page.

OK let me explain you:

  1. I am navigating to that page “Accesdmin/EspaceAdministrator” because i have a specific navbar for the users who are administrator or who is in the group administrator later. So when you connect, if you are one of them, you will redirect to the “Accesdmin/EspaceAdministrator”. The function here is ‘home’ the template concerned is styleAppv3.html. The latest html file i sent.
  2. From this side or administrator navbar (styleAppv3.html), you will click on this link —Groupe– to go to the first html file i had been sent to input data into ‘libGroup’ and click on submit button which is named ‘Ajouter’ to sumit the form. The function here in the view is ‘createGroupok’. My problem is that when i click on the link {% url ‘groupAddok’ %}, i get the page of creation ‘user groupe’ and the method is GET(that’s normal) but when i try to click on the button ‘Ajouter’ to submit the data, i am still on GET method instead of PUT method which specify into my html file. Thanks a lot and i am still available for more informations.

Ok, but you haven’t shown that in the logs. You haven’t identified what you’re seeing that is an indication of this issue.

sorry, i’m really new here and i appreciate a lot what you do.

No worries, we’re here to try and help.

Please post the more complete log showing the error that you are describing.

Thanks.
I have no more log. I just sent you the result on Terminal when i try click on this link —Groupe–:
[03/Oct/2024 23:27:08] “GET /AccessAdmin/EspaceAdministrator HTTP/1.1” 200 6704
[03/Oct/2024 23:27:08] “GET /static/css/all.min.css HTTP/1.1” 404 1985
La valeur de la methode est avec la form est invalide –
GET
and i click on button ‘Ajouter’ to submit the post form:
[03/Oct/2024 23:27:15] “GET /AccessAdmin/groupAddok HTTP/1.1” 200 6994
[03/Oct/2024 23:27:15] “GET /static/css/all.min.css HTTP/1.1” 404 1985

May be you could help me how could I get the more complete log showing the error that i am describing?.

Ok, I see now.

Your submit button is not within your <form ...> ... </form> element.

You have:

<form ...>
  ...
</form>
<input type="submit">

instead of:

<form ...>
  ...
<input type="submit">
</form>

Hello,
Since the last time you replied, i put my submit button inside <form ...> ... </form> element but it makes something wrong. My script doesn’t work well.
When the button “b5” clicked with ouside <form ...> ... </form> element, the buttons b5 and b4 deseapper and the buttons b1,b2,b3 appear. This work normaly whe my code about button is not inside the <form ...> ... </form> element…
When i put inside and i press or click the button b5, it reverses. It means i still get the buttons b4 and b5. Please help.