0

I can't pass inputted in HTML form value to python via request.form.get('name'). I watсhed youtube and found original function request.form['name'] that doesn't work as well. Even tried to pass values to js first and then pass it to python, didn't help.

HTML page from which I want to get input:

 <script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-
  validator/0.11.9/validator.min.js"></script>
 <div id="reg">
 <div class="container w">
<div class="row centered">
<br>
  <div class="col-lg-5 col-lg-offset-3">
<form data-toggle="validator" role="form">
<div class="form-group">
<label for="inputName" class="control-label">Name</label>
<input name="userus" autocomplete="off" autofocus  type="text" class="form-
 control" id="inputName" placeholder="Your name" required>
<div class="help-block">Input your name</div>
</div>
<div class="form-group">
<label for="inputPassword" class="control-label">Password</label>
<div class="form-inline row">
  <div class="form-group col-sm-6">
    <input name="password" autocomplete="off" autofocus type="password" 
 data-minlength="3" class="form-control" id="inputPassword" 
 placeholder="Password" required>
    <div class="help-block">Minimum of 3 characters</div>
  </div>
  <div class="form-group col-sm-6">
    <input name="confpassword" autocomplete="off" autofocus type="password" 
   class="form-control" id="inputPasswordConfirm" data-
    match="#inputPassword" data-match-error="Whoops, these don't match" 
    placeholder="Confirm" required>
    <div class="help-block with-errors"></div>
  </div>
 </div>
 </div>
 <div class="form-group">
 <button type="submit" class="btn btn" id="bt1">Submit</button>
 </div>
 </div> </div> </div>
 <div>
 {{nom1}}, {{nom2}}, {{nom3}}
 </div>
 </form>

Original code (python) of the page where I want to recive values:

@app.route("/register", methods=["GET", "POST"])
def register():

if request.method == "POST":

    #ensure username was submitted
    name = request.form.get("userus")
    password = request.form.get("password")
    confpassword = request.form.get("confpassword")
    if not name:
        return render_template("register.html")

    #ensure password was submitted
    elif not password:
        return render_template("register.html")

    # ensure password was submitted
    elif not confpassword:
        return render_template("register.html")

    # checking database for failure
    result = db.execute("INSERT INTO users (name,password) VALUES(:name,:haspass)", name=request.form.get("inputName"), 
    #haspass=CryptContext.hash(request.form.get("password")) )
    haspass=pwd_context.hash(request.form.get("password")) )
    if not result:
        return render_template("register.html", nom1=name, nom2=password, nom3=confpassword)
    #redirect user to home page
    return render_template("register.html", nom1=name, nom2=password, nom3=confpassword)
else:
    return render_template("register.html")

I use bootstrap validator (1000hz) you can see it in HTML code and all my imports (everything I found in pset7,8

from cs50 import SQL
from flask import Flask, flash, redirect, render_template, request, session, 
url_for, jsonify
from flask_session import Session
from passlib.apps import custom_app_context as pwd_context
from tempfile import mkdtemp
from functools import wraps
from flask_jsglue import JSGlue
import os
import re

Found one just maby interesting thing: enter image description here

It can see submited values, but I dont know how to pass them to python

Help me to pass these values (name and password) to python or should I just delete bootstrap validation?

2

It's not so much you "can't" pass it as you "don't" pass it. There is no input element whose name attribute is "name".

After edit: from the screenshot, you should notice it's using a "get" method because, well it says so, and there is a the query string. You'll either need to add a method="post" attribute to the form element, or test for a GET and look at request.args instead of request.form.

1
  • Edited my mistake but it still doesn't work. Added a screen of flask run log window, it can see values inputted in forms, but doesn't want to pass them to python Aug 2 '17 at 15:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .