0

I am trying to create simple login in flask but i am not getting data in blackened

my html look like

{% extends "layouts/home.html" %}
{% block body %}
{% block css %}
        <link rel=stylesheet type=text/css href="{{ url_for('static', filename='css/v2/login.css') }}">
{% endblock %}
<div class="container">
    <div class="row">
        <div class="col-sm-6 col-md-4 col-md-offset-4">
            <div class="account-wall">
                <img class="profile-img" src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=120"
                    alt="">
                <form role="form" class="form-signin" method="post" enctype="multipart/form-data" action="{{url_for('login_success')}}">
                <input type="text" class="form-control" placeholder="Email" required autofocus>
                <input type="password" class="form-control" placeholder="Password" required>
                <button class="btn btn-lg btn-primary btn-block" type="submit">
                    Sign in</button>
                <label class="checkbox pull-left">
                    <input type="checkbox" value="remember-me">
                    Remember me
                </label>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}

my flask code look like

@app.route('/login')
def login():
    return render_template('index.html')


@app.route('/login-success', methods=['POST'])
def login_success():
    if request.form:
        print request.form
        return redirect(url_for('login'))
    return redirect(url_for('login'))

but request.form is none i am not able to understand what could be possibly wrong

2 Answers2

0

You should add the property 'name' to all your fields, for example:

 <input type="text" name="email" class="form-control" placeholder="Email" required autofocus>

A better way to go if you're going to deal with forms is the Flask-WTF package.

Also note you're question has been asked already, e.g., here. For these matters, there's usually an answer on stackoverflow, just look for it. It will save you time and avoid duplicates on this site.

Community
  • 1
  • 1
GG_Python
  • 3,436
  • 5
  • 34
  • 46
0

It's not like you are not getting output of request.form .If you try to print request.form then must be getting immutable dictionary in back-end but it must be empty because whenever you try to post a form then http send form data in form object . But in your case you are not giving key of object so yo are getting empty dictionary . If you give key then you will get output.

In your html your should write like

<input type="text" name ="email" class="form-control" placeholder="Email" required autofocus>

And in back-end try something like this

print request.form['email]