Day 080 - Project 80 : Actually logging in!

If you have any questions, comments or issues with this project please post them here!

The “Fix my code” part is missing two errors in the solution, so the solution is not executable.

Line 5: Missing an “@” in front
Line 11: “David” needs a capital “D”

1 Like

Could you sumarize the lesson? I need to use the skill but haven’t made it to this one.

You could go to the Replit YouTube Channel.
Day 80 Video

2 Likes

Thanks, I forgot about that :smiley:

I take it back I’m on like day 40 so I don’t know any html or what flask is

from flask import Flask, request

app = Flask(__name__, static_url_path="/static")

@app.route('/login', methods=["POST"])
def prosess():
  page=""
  form = request.form
  if form["Username"] == "Gaurav291" and form["Password"] == "p23anther":
    page += """<html>
    <head>
    <title>Logged In</title>
    <link href="/static/Css/style_l.css" rel="stylesheet" >
    </head>
    <body>
    <h1>You are logged in </h1>
    </body>
    </html>"""
  elif form["Username"] == "Gaurav591" and  form["Password"] == "p23anther291": 
    page += """<html>
    <head>
    <title>Logged In</title>
    <link href="/static/Css/style_l.css" rel="stylesheet" >
    </head>
    <body>
    <h1>You are logged in </h1>
    </body>
    </html>"""
  elif form["Username"] == "Vinay291" and form["Password"] == "p23anther591":
    page += """<html>
    <head>
    <title>Logged In</title>
    <link href="/static/Css/style_l.css" rel="stylesheet" >
    </head>
    <body>
    <h1>You are logged in </h1>
    </body>
    </html>"""
  else:
    page += """<html>
    <head>
    <title>Logged In</title>
    <link href="/static/Css/style_r.css" rel="stylesheet" >
    </head>
    <body>
    <h1>Incorrect Passward and Username</h1>
    </body>
    </html>"""
  return page

@app.route('/')
def index():
  page = """<!DOCTYPE html>
<html>
  <head>
    <titl>Login Page</titl>
    <link href="/static/Css/style.css" rel="stylesheet">
  </head>
  <body>
    
    <h1>Login</h1>
    <form method="post" action="/login">
      <p>Username: <input type="text" name="Username" required></p>
      <p>Email: <input type="Email" name="Email"></p>
      <p>Password: <input type="Password" name="Password" required></p>
      <button type="submit">Login</button>
    </form>
  </body>
</html>"""
  return page

app.run(host="0.0.0.0", port="81")`

This Code can also be written in this form ( is this is right)

Yes, you can write the HTML inside main.py. Kind of unreadable imo though.

1 Like

Question: I have set up a Flask server with the correct app route and linked my HTML file with that correctly I beleive. still, the server is not running. Afaiu code is fine. Please guide me as I am beginner in programming


Repl link: https://replit.com/@mayankk985/Day80100Days#main.py

from flask import Flask, request

app = Flask(__name__)


@app.route("/process", methods=["POST"])
def process():
    form = request.form
    page = ""

    if form["baldies"] == "david":
        page += f"You're alright {form['username']}"
    else:
        page += f"You've picked wrong {form['username']}"
    return page


@app.route("/")
def index():
    page = ""
    f = open("index.html", "r")
    page = f.read()
    f.close()
    return page


app.run(host="0.0.0.0", port=81)

<!DOCTYPE html>
<html>
  
  <body>
  <form method = "post" action="/process">
    <p>Name: <input type="text" name="username" required> </p>
    <p>Email: <input type="Email" name="email"> </p>
    <p>Website: <input type="url" name="website"> </p>
    <p>Age: <input type="number" name="age"> </p>
    <p><input type="hidden" name="userID" value="232"> </p>

    <p>
      Fave Baldy: 
      <select name="baldies">
        <option value ='david'>David</option>
        <option value= 'luc'>Jean Luc Picard</option>
        <option value='yul'>Yul Brynner</option>
      </select>
    </p>

    <button type="submit">Save Data</button>
  </form>
  
  </body>
  </html>

Hi @mayankk985 interesting error message in your code (keep it SFW please, as per Replit Ask Community Standards). When I fork the Repl it works fine for me, asks for a username, email and password.

Do you still see the same error when you run your Repl?

2 Likes

Hey @IanAtReplit I am sorry about that msg,I was going crazy while debugging it, I didn’t notice that before posting the link here🙃. unfortunately it’s still not working. I don’t get any error message on console, however it not opening in webview or on browser. on the browser/ webview it says ’ It looks like day80100days.mayankk985.repl.co closed the connection’

Try using

app.run(host='0.0.0.0', port=8080) 

instead of port 81. Replit might be using the other ports.

1 Like

As far as I’m aware, pid1 (Replit’s init program, which is the only program that Replit runs inside repls that accepts TCP connections, other than a VNC server, which listens on port 5900 and is only started when graphical programs are used) currently only listens on the following addresses:

  • 127.0.0.1:8283
  • 0.0.0.0:22

If I missed any, feel free to edit this.

1 Like

It seems like your replit account doesn’t have a TLS certificate (for *.mayankk985.repl.co) right now, try waiting a while.

1 Like

After day 80 I tried to write a program where I used Pyjokes library with a simple form (to select the language), however once inside the form I’m struggling to make the “next one” (reload) button work. Could anyone help me, please? :pray:t2:

https://replit.com/@Sibelius11/Jokesa

I have managed to do the form by myself for a set of data for one user but had to look at the solution for the dictionary of data and still didn’t manage to get the return for login to say “Welcome {USER}” with the {USER} being from the form.user