473,666 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question about endpoint in flask

3 New Member
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.
Expand|Select|Wrap|Line Numbers
  1. __author__ = 'Administrator'
  2. from app import app,db,lm,oid
  3. from flask import render_template,flash,redirect,session,url_for,request,g
  4. from flask.ext.login import login_user,logout_user,current_user,login_required
  5. from models import User
  6. from form import LoginForm#,EditForm
  7. from datetime import datetime
  8.  
  9. @app.route('/')
  10. @app.route('/index')
  11. @login_required
  12. def index():
  13.     user = g.user
  14.     #user = { 'nickname': 'Miguel' } # fake user
  15.     posts = [ # fake array of posts
  16.         {
  17.             'author': { 'nickname': 'John' },
  18.             'body': 'Beautiful day in Portland!'
  19.         },
  20.         {
  21.             'author': { 'nickname': 'Susan' },
  22.             'body': 'The Avengers movie was so cool!'
  23.         }
  24.     ]
  25.     return render_template("index.html",
  26.         title = 'Home',
  27.         user = user,
  28.         posts = posts)
  29. @lm.user_loader
  30. def load_user(id):
  31.     return User.query.get(int(id))
  32. @app.route('/login',methods=['GET','POST'])
  33. @app.before_request
  34. def before_request():
  35.     g.user = current_user
  36.  
  37. def login():
  38.     if g.user is not None and g.user.is_authenticated:
  39.         return redirect(url_for('index'))
  40.     form = LoginForm()
  41.     print form.openid.data
  42.     if form.validate_on_submit():
  43.         session['remember_me'] = form.remember_me.data
  44.         a= User.query.get(2).nickname
  45.         print 'dataall   '+str(a)
  46.         user = User.query.filter_by(nickname=form.openid.data).first()
  47.         print 'query result  ' + str(user)
  48.                 if user :
  49.            print 'user start'
  50.                       login_user(user)
  51.            return redirect( url_for('index'))
  52.            print 'user done'
  53.     return render_template('login.html',title = 'Sign In',form = form,providers = app.config['OPENID_PROVIDERS'])
  54.  
  55.  
  56. @app.route('/user/<nickname>')
  57. @login_required
  58. def user(nickname):
  59.     user = User.query.filter_by(nickname = nickname).first()
  60.     if user == None:
  61.         flash('User' + nickname +"not found.")
  62.         return redirect(url_for('index'))
  63.     posts = [
  64.         {'author':'user','body':'Test post #1'},
  65.         {'author':'user','body':'Test post #2'}
  66.     ]
  67.     return render_template('user.html',user=user,posts =posts)
html file is below
Expand|Select|Wrap|Line Numbers
  1. <html> <head>
  2.     {% if title %}
  3.     <title>{{title}} - microblog</title>
  4.     {% else %}
  5.     <title>microblog</title>
  6.     {% endif %}
  7.   </head> <body> <div>Microblog:
  8.      <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>
  9.     {% with messages = get_flashed_messages() %}
  10.     {% if messages %}
  11.     <ul>
  12.     {% for messages in messages %}
  13.         <li>{{ message }}</li>
  14.     {% endfor %}
  15.     </ul>
  16.     {% endif %}
  17.     {% endwith %}
  18.     {% block content %}{% endblock %}
  19.   </body> </html>
Jun 27 '19 #1
0 1333

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1485
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.
4
2160
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
0
3924
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.. ...
0
1483
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...
3
4416
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...
8
2137
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
0
1521
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)
0
1712
maylortaylor
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" ...
1
1813
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=)...
0
1468
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.
0
8449
marktang
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...
0
8876
Oralloy
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...
1
8556
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,...
0
7387
agi2029
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...
1
6198
isladogs
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...
0
5666
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();...
0
4198
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...
1
2774
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
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.