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ā
Could you sumarize the lesson? I need to use the skill but havenāt made it to this one.
Thanks, I forgot about that
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.
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?
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.
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.
It seems like your replit account doesnāt have a TLS certificate (for *.mayankk985.repl.co
) right now, try waiting a while.
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?
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