hi there,when learning flask,i have confronted a question,which is "BuildError: Could not build url for endpoint 'login'. Did you mean 'index' instead?",my code is below. - __author__ = 'Administrator'
-
from app import app,db,lm,oid
-
from flask import render_template,flash,redirect,session,url_for,request,g
-
from flask.ext.login import login_user,logout_user,current_user,login_required
-
from models import User
-
from form import LoginForm#,EditForm
-
from datetime import datetime
-
-
@app.route('/')
-
@app.route('/index')
-
@login_required
-
def index():
-
user = g.user
-
#user = { 'nickname': 'Miguel' } # fake user
-
posts = [ # fake array of posts
-
{
-
'author': { 'nickname': 'John' },
-
'body': 'Beautiful day in Portland!'
-
},
-
{
-
'author': { 'nickname': 'Susan' },
-
'body': 'The Avengers movie was so cool!'
-
}
-
]
-
return render_template("index.html",
-
title = 'Home',
-
user = user,
-
posts = posts)
-
@lm.user_loader
-
def load_user(id):
-
return User.query.get(int(id))
-
@app.route('/login',methods=['GET','POST'])
-
@app.before_request
-
def before_request():
-
g.user = current_user
-
-
def login():
-
if g.user is not None and g.user.is_authenticated:
-
return redirect(url_for('index'))
-
form = LoginForm()
-
print form.openid.data
-
if form.validate_on_submit():
-
session['remember_me'] = form.remember_me.data
-
a= User.query.get(2).nickname
-
print 'dataall '+str(a)
-
user = User.query.filter_by(nickname=form.openid.data).first()
-
print 'query result ' + str(user)
-
if user :
-
print 'user start'
-
login_user(user)
-
return redirect( url_for('index'))
-
print 'user done'
-
return render_template('login.html',title = 'Sign In',form = form,providers = app.config['OPENID_PROVIDERS'])
-
-
-
@app.route('/user/<nickname>')
-
@login_required
-
def user(nickname):
-
user = User.query.filter_by(nickname = nickname).first()
-
if user == None:
-
flash('User' + nickname +"not found.")
-
return redirect(url_for('index'))
-
posts = [
-
{'author':'user','body':'Test post #1'},
-
{'author':'user','body':'Test post #2'}
-
]
-
return render_template('user.html',user=user,posts =posts)
html file is below - <html> <head>
-
{% if title %}
-
<title>{{title}} - microblog</title>
-
{% else %}
-
<title>microblog</title>
-
{% endif %}
-
</head> <body> <div>Microblog:
-
<a href="{{ url_for('index') }}">Home</a> <a href="{{ url_for('user', nickname = g.user.nickname) }}">Your Profile</a> <a href="{{ url_for('logout') }}">Logout</a> </div> <hr>
-
{% with messages = get_flashed_messages() %}
-
{% if messages %}
-
<ul>
-
{% for messages in messages %}
-
<li>{{ message }}</li>
-
{% endfor %}
-
</ul>
-
{% endif %}
-
{% endwith %}
-
{% block content %}{% endblock %}
-
</body> </html>
0 1323 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Richard L Rosenheim |
last post by:
I'm playing around with setting up a multicast socket. I can create a
socket for sending, and I can one that receives. Is it possible to create
one socket that can do both?
The code I've been...
|
by: 0to60 |
last post by:
I have a question about socket programming in general.
Exactly what happens behind the scenes when I one socket connects to a
different socket in listen mode? Using the dotnet framework, I...
|
by: ronscottlangham |
last post by:
I have a WCF Web Service that I develop using the ASP.NET Development
Server in Visual Studio. In release, the web service will support both
HTTP and HTTPS. Initially I had only HTTP configured in...
|
by: rkprasad |
last post by:
I am able to create BASIC-CLEAR-INTEGRATED sql http endpoint and consume it on a LAN. But i am not able to consume the created endpoint on inter domain network. If i create endpoint on a server...
|
by: Lance Wynn |
last post by:
Hello,
I am receiving this error when trying to instantiate a webservice component.
I have 2 development machines, both are XP sp2 with VS 2008 installed. On
one machine, the code works fine. On...
|
by: Frank Hauptlorenz |
last post by:
Hello out there,
I changed an existing and good working webservice from an wsHttpBinding
to an NetTcpBinding.
This is working (after trying some time) and has real a better performance!
But...
|
by: keelo |
last post by:
I have a small c++ .net program that is intended to be a simple UDP server; however, I just want to start blasting out packets when a connection is made.
After setup,
Socket^ socket = gcnew...
|
by: maylortaylor |
last post by:
I have a pretty simple TimeClock application written in VB (.net4) that I'm trying to add to. The addition will allow the user to change where the service is coming from.
In short, I want to be...
|
by: vento |
last post by:
I have struggled to get this code to work for some days now. This should be just simple web form where text is added to 2 fields and posted to the Sqlite-database.
I am able to display data from...
|
by: nishank05 |
last post by:
I want to integration CC Avenue payment gateway with Flask. Is there a ready made library for that or is there a way I can do it. Seems CC Avenue officially supports ASP, ASP.net JSP and PHP only.
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |