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 1333 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 basing my work on is the code in "IP Multicasting in C#"
by Gary Brewer, http://www.codeproject.com/csharp/multicast.asp).
The following is the code snippet that I have. I'm able to receive packets,
but sending is hanging up.
|
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 create a
socket, bind it to a port, put it in listen mode, and then n sockets can
connect to it. The code:
Socket newSocket = listeningSocket.Accept();
returns a socket. I can communicate on newSocket, and listeningSocket goes
|
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 my web.config
file, but have now added the HTTPS endpoints and bindings. When I do
this, I now get an error when trying to connect to the development
server from my client using HTTP. On the client side, I get the
error..
...
|
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 having live IP and try to access it as http://59.165.20.29/SqlHttpEndPointPath?WSDL from a LAN which has its own proxy then I am not able to access it ; and get HTTP 500/HTTP 501 error in the browser.
In a different way i create an sql http endpoint...
|
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 the other machine I get the error upon
instantiating the service client. I add the reference by choosing Add
Service Reference from the project menu, and pointing to the remote wsdl
file. I can't seem to find what the difference between the two...
| |
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 one thing is strange: when I'm now actualising the web reference
from within VS2008, VS2008
creates a 2nd endpoint config in my app.conf.
The endpoint is exactly the same as the existing but the name and
|
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 Socket(AddressFamily::InterNetwork, SocketType::Dgram, ProtocolType::Udp);
IPEndPoint^ ipep = gcnew IPEndPoint(IPAddress::Any, 54321);
socket->Bind(ipep);
while(true)
|
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 able to programatically change the Endpoint Address in the App.Config file.
For reference:
<client>
<endpoint address="net.tcp://localhost:8090/MyService/TimeClockService"
binding="netTcpBinding"
...
|
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 db to index.html but accessing below address results to 405 error -'The method is not allowed for the requested URL' when I try to access
http://localhost:5000/post. What is wrong with app.py file likely relating to @app.route('/post', methods=)...
|
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.
Any help will be highly appreciated.
Best regards.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |