Problem with code in settings

*Question:
Problem with “GET /traitement HTTP/1.1” in settings

Current behavior:
I’m doing an assignment in computer science (in french language) and when I fill out the cells and should be redirected to the next page, only a white screen is displayed. I checked everything, but I didn’t find where is error. In my settings it shows that I have a problem with “GET /traitement HTTP/1.1”

Desired behavior
When you fill out the form and click “tirage au sort” you should be redirected to the next page, where it says whether you won or lost.

(Even my teacher doesn’t know where the problem is. Perhaps there are geniuses sitting here who can help me.)

Repl link:
https://replit.com/@1ereNSI23241spe3Gr10/TP-4-Serveur-liliavorozhbyt

code snippet
1 Like

Hi there @liliavorozhbyt and welcome to the community!

The link you posted redirect to a 404 page, perhaps your repl is a private one?

It’s possible, but I can’t fix it, because it’s a teacher’s server. But anyway, thanks for your feedback

You can post the code of your project here and we can try to help you, use the preformatted text button to include your code in this post.

1 Like

They said it was an assignment so it’s probably Teams for Edu.

Oh, I tought that Teams for Edu was terminated

It’s been deprecated, but you can still use it until August.

2 Likes

No, it’s not that. Why do you think it’s Teams Edu? This task is from my computer class

I already doubt this, since there are a lot of pages of code. And + some lines in French, if that doesn’t bother you

Oh, I have en idea. It seems to me that it would be better if I sent the task itsel here too. The problem starts from point 9, in the settings you can translate into English

It’s a first page

from flask import Flask, render_template, request 
import random

app = Flask(__name__)
@app.route("/")
def formulaire_mars():
    return render_template("index.html")
    
@app.route("/traitement", methods=["POST"])
def resultat():
    nom = request.form["nom"]
    motivation = request.form["texte"]
    alea = random.randint(1,1000)
    if alea == 666:
        return render_template("gagne.html", le_nom=nom, 
         texte_motiv=motivation)
    else:
        print("Z")
        return render_template("perdu.html", le_nom=nom)
        
@app.route("/mars")
def affiche_mars():
    return render_template("mars.html")
app.run(host='0.0.0.0', port=8080)
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>TP02 Formulaire</title>
    <link href="/static/style.css" rel="stylesheet" type="text/css"/>
  </head>
  <body>
    <h1>Objectif Mars !</h1>
    <p>Une chance sur mille d'être sélectionné pour un voyage sur Mars.</p>
    <a href="mars.html">Voir Mars</a>
    <p>Tentez votre chance en remplissant le formulaire.</p>
    <form method="POST" action="/traitement">
       <div>
            <label>Nom : </label><br>
            <input type="text" id="nom" name="nom">
        </div>
        <div>
            <label>Date de naissance :  </label><br>
            <input type="date" id="date_n">
        </div>
        <div>
            <label>Avez-vous déjà été sur la Lune ?</label><br>
            <select id="lune">
                <option value=""> Choisir une option</option>
                <option value="Oui"> Oui</option>
                <option value="Non"> Non</option>
                <option value="Peut-etre"> Peut-être</option>
            </select>
        </div>
        <div>
            <label>Avez-vous le mal de mer en fusée ?</label><br>
            <label>Oui : </label>
            <input type="radio" id="fusee_oui" name="fusee" value="oui"><br>
            <label>Non : </label>
            <input type="radio" id="fusee_non" name="fusee" value="non"><br>
            <label>Je ne sais pas : </label>
            <input type="radio" id="fusee_jnsp" name="fusee" value="jnsp">
        </div>
        <div>
            <label>Pour avoir un joli scaphandre, donnez vos couleurs préférées :</label><br>
            <label>Bleu : </label>
            <input type="checkbox" id="bleu" value="bleu"><br>
            <label>Rouge : </label>
            <input type="checkbox" id="rouge" value="rouge"><br>
            <label>Rose : </label>
            <input type="checkbox" id="rose" value="rose"><br>
        </div>
        <div>
            <label>Pourquoi voulez-vous aller sur Mars ?</label>
            <textarea id="texte" rows="5" cols="42" placeholder="Réponse :" name = "texte"></textarea><br>
        </div>
        <div>
            <button type="button" id="btn" onclick="valide_formulaire()">Go to Mars !</button>
            <button type="submit" id="btn2" disabled>Tirage au sort</button>
        </div>
        <div id="info"></div>
        </form>
      <script src="/static/script.js"></script>
  </body>
</html>

Two more, they are not important I think, but my project should be forwared to there pages. In short, just in case, I’ll post them too

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Perdu</title>
    <link href="/static/style.css" rel="stylesheet" type="text/css"/>
  </head>
  <body>
      <h1>Dommage vous avez perdu!</h1>
  </body>
</html>

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Gagné</title>
    <link href="/static/style.css" rel="stylesheet" type="text/css"/>
  </head>
  <body>
   <h1>Bravo, {{le_nom}}! Vous êtes sélectionné pour un voyage sur Mars.</h1>
   <p> Nous vous contacterons bientôt. S'il y a trop de gagnants nous sélectionnerons le plus motivés. Nous vous rappelons ce que vous nous avez écrit.</p>
   <p> {{texte_motiv}} </p>
</body>
</html>

If anything, I warned you that there is a lot of code. If anyone can find the problem I will bless him haha

It’s because since the link you provided is giving an 404 error, this usually happens when the repl is private or is inside the Teams For Edu. Are you sure that you build the code in replit? Copy the URL link from where your code is and post it here again.

About the code you provided… is not providing much information too… I noticed that you have two buttons, and the submit button (<button type="submit" id="btn2" disabled>Tirage au sort</button> ) is disabled.

Another thing is that you have a JavaScript function valide_formulaire() attached to the “Go to Mars !” button, but you didn’t provided the script… If this script is meant to enable the submit button or validate the form… it can be a problem too, so make sure to validate this.

I think I understand what the problem. It was a bug in the repl, when I tried to open the project in the browser everything worked. Although it didn’t work before, but apparently it happens.

Thank you for paying attention to my problem! You will be a genius to me. Do you mind being friends haha?

Oh sure, no problem!

Yes as stated but to verify

        <div>
            <button type="button" id="btn" onclick="valide_formulaire()">Go to Mars !</button>
            <button type="submit" id="btn2" disabled>Tirage au sort</button>
        </div>

You have btn with onclick= but your desired button “btn2” is disabled, so this will have no function.

How to contact you? :smiley: