Reputation: 71
I am successfully able to deploy the application without any errors but when I access the app URL, I get an error :
Error: Not Found The requested URL / was not found on this server.
When I access the error log on the cloud console, I see the error :
ValueError: virtualenv: cannot access flask: No such virtualenv or site >directory
My codes are listed as follows :
from flask import Flask, render_template, request,url_for,redirect,flash
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
app = Flask(__name__)
app.secret_key = 'some_secret'
engine = create_engine("postgresql://postgres:sona@localhost:1234/users")
db = scoped_session(sessionmaker(bind=engine))
@app.route("/")
def index():
return render_template("index.html")
@app.route("/register")
def register():
return render_template("register.html")
@app.route("/hello", methods=["GET","POST"])
def hello():
if request.method=="GET":
return redirect(url_for('index'))
else:
fname = request.form.get("fname")
fname = fname.capitalize()
lname = request.form.get("lname")
lname = lname.capitalize()
username = request.form.get("username")
password = request.form.get("password")
email = request.form.get("email")
mobile = request.form.get("mobile")
age = request.form.get("age")
location = request.form.get("location")
if fname == '' and age == '':
flash('Invalid Credentials !!')
return render_template("register.html",message='True')
else:
db.execute("INSERT INTO users(fname, lname, username, password,
email, mobile, age, location) VALUES (:fname, :lname,
:username, :password,
:email, :mobile, :age, :location)",
{"fname": fname, "lname": lname,"username": username,
"password": password, "email": email, "mobile": mobile,
"age": age, "location": location})
db.commit()
users = db.execute("SELECT * FROM users").fetchall()
return render_template("hello.html",fname=fname,lname=lname,
username=username,password=password,
email=email,mobile=mobile,age=age,
location=location,users=users)
if __name__ == '__main__':
app.debug = True
app.run()
from google.appengine.ext import vendor
# Add any libraries installed in the "lib" folder.
vendor.add('flask')
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /static
static_dir: static
- url: /.*
script: main.app
Flask==0.12.2
Werkzeug<0.13.0,>=0.12.0
Rest all the HTML files are fine and I am able to run the application successfully on localhost server. Also need guidance to connect the application to postgresql instance on the cloud. Also the application gives no error when testing it on ocalhost on cloud sdk shell.
Upvotes: 2
Views: 1665
Reputation: 39814
Rename application.py
to main.py
(or, non-standard, change in your app.yaml
file main.app
with application.app
, but not both). The name of the module containing the app
variable must match. From the script row in the Handlers element table from the app.yaml
reference:
A
script:
directive must be a python import path, for example,package.module.app
that points to a WSGI application. The last component of ascript:
directive using a Python module path is the name of a global variable in the module: that variable must be a WSGI app, and is usually calledapp
by convention.
Your vendor.add('flask')
suggests you used a non-standard dir name for 3rd party libs - flask
instead of lib
- be sure to adjust the docs info accordingly. But I'd suggest reverting to the standard naming convention, unless you're intentionally looking for trouble.
Drop the if __name__ == '__main__':
section - that's not how Flask works on GAE.
I'd strongly suggest carefully going through the Getting Started with Flask on App Engine Standard Environment (including the code examples).
Upvotes: 2