Saturday 15 February 2014

python - ValueError: View function did not return a response in flask -



python - ValueError: View function did not return a response in flask -

so there several of questions asked , error means function has homecoming value, or means should homecoming something.

i have in routes.py file still not working.

here code route.py

from flask import * functools import wraps app = flask(__name__) app.secret_key = "my precious" @app.route('/') def home(): homecoming render_template('home.html') @app.route('/welcome') def welcome(): homecoming render_template('welcome.html') @app.route('/logout') def logout(): session.pop('logged_in',none) homecoming redirect (url_for('home')) @app.route('/hello') def hello(): homecoming render_template('hello.html') @app.route('/log', methods=['get','post']) def log(): error = none if request.method == "post": if request.form['username'] != 'admin' or request.form['password'] != 'admin': error = "invalid credentials" else: session['logged_in'] = true homecoming redirect (url_for('hello')) homecoming render_template('log.html', error=error) if __name__ == '__main__': app.run(debug=true)

code log.html

{% extends "templates.html" %} {% block content %} <h1>login</h1> {% if error %} <p class=error> <strong> error: </strong> {{ error }} {% endif %} <form action="" method="post"> <dl> <dt>username: <dt><input type="text" name="username" value="{{ request.form.username }}"> <dt>password: <dd><input type="password" name="passowrd"> </dl> <p><input type="submit" value="login"> </form> {% endblock %}

code templates.html

<html> <head> <title>flask tutorial (part 1)</title> </head> <header> <div class="navbar navbar-inverse"> <div class="navbar-inner"> <a class="brand" href="/">real python (for web!)</a> <ul> <li><a href="/welcome">welcome</a></li> <li><a href="/log">login</a></li> </ul> </div> </div> </header> <body> <div class="container"> {% block content %} {% endblock %} </div> </body> </html>

code home.html

{% extends "templates.html"%} {% block content %} <div class="jumbo"> <h2>welcome flask</h2> <br/> <p>click <a href="/welcome">here</a> go welcome page</p> </div> {% endblock %}

code hello.html

{% extends "templates.html" %} {% block content %} <h2>welcome! logged in.</h2> {% endblock %}

code welcome.html

{% extends "templates.html"%} {% block content %} <h2>sample</h2> <p>lorem ipsum dolor sit down amet, consectetur adipiscing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim advertisement minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> <p>lorem ipsum dolor sit down amet, consectetur adipiscing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim advertisement minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> {% endblock %}

can help me going wrong? in advance

the log() method not homecoming response if you're accessing via get. question bit uninformative error happening, can deduce.

edit: looking video, indeed log method causing trouble. you've accidentally indented deep.

@app.route('/log', methods=['get','post']) def log(): error = none if request.method == "post": if request.form['username'] != 'admin' or request.form['password'] != 'admin': error = "invalid credentials" else: session['logged_in'] = true homecoming redirect (url_for('hello')) homecoming render_template('log.html', error=error)

python flask

No comments:

Post a Comment