Python Forum

Full Version: Need help with Flask App
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm working from a basic skeleton code to build up this app but i have been facing issues just trying to initially run the app. after installing flask and flask-sqlalchemy when i type python3 app.py, the app starts with this

"Serving Flask app "app" (lazy loading)

Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
Debug mode: on
Restarting with stat
Debugger is active!
Debugger PIN: 147-926-310
Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)" then when clicking the link i run into this issue:"
but when i click on the link the build gets a error:
"werkzeug.routing.BuildError: Could not build url for endpoint 'contacts'. Did you mean 'static' instead?"


i also noticed im not getting flask-SQLAlchemy loaded even though i have installed it using pip3 install -U Flask-SQLAlchemy
and it was successful.
[Image: 44hcxYx]
From the information you provided I can't really tell, if you could post part of the code where you do the 'routing' as well, that would be great. Also a full error traceback is always helpful.

Regarding the flask_sqlalchemy lib, make sure that your IDE is using the same python interpreter as the one you've installed the library in.
please, don't post images of code and error.
Use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Provide all relevant info
well it seems that im getting this error in VSCode:
"{
"resource": "/C:/Python38/lib/site-packages/flask_sqlalchemy/__init__.py",
"owner": "_generated_diagnostic_collection_name_#2",
"severity": 4,
"message": "Import \"flask_sqlalchemy.model\" could not be resolved",
"source": "Pylance (reportMissingImports)",
"startLineNumber": 22,
"startColumn": 6,
"endLineNumber": 22,
"endColumn": 28
}
i did use the terminal in vscode to make sure i had installed flask and flask-sqlachemy, but for some reason i get this error in the code.

this is th main app.py file:
from flask import Flask, redirect, url_for, render_template, request, flash
from models import db, Contact

# Flask
app = Flask(__name__)
app.config['SECRET_KEY'] = '847rc0ruprguew09grywe8457398un9xfnhf7h302-3ru1430ntq=4r84230t723ct3'
app.config['DEBUG'] = True

# Database
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///book.sqlite'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['DEBUG'] = True
db.init_app(app)
db.create_all()


@app.route("/")
def index():
    '''
    Home page
    '''
    return redirect(url_for('contacts'))


'''
Create new contact
'''


'''
Delete contact
'''


'''
Edit contact
'''


'''
Show alls contacts
'''


'''
Search contacts
'''



if __name__ == "__main__":
    app.run(port=3000)
Error:
Exception has occurred: ModuleNotFoundError No module named 'flask_sqlalchemy'
Well you are redirecting from index to contacts endpoint, but I don't see the contacts endpoint defined anywhere
This was the skeleton project i received from the employer to work on and i have not done anything to it and i though it should have run for me to working on it.
(Oct-01-2020, 08:02 PM)mlieqo Wrote: [ -> ]Well you are redirecting from index to contacts endpoint, but I don't see the contacts endpoint defined anywhere

where would i find this endpoint "contacts" and where should it be defined?
between the static folder, templates, and web folders.
but what really stands out to me is the issue with flask_sqlalchemy not being imported with the errors just states Import "flask_sqlalchemy" could not be resolved Pylance (reportMIssingImports)
well I supose it should be right below this part
'''
Show alls contacts
'''
Smile

you should probably read up on flask, here is a quickstart - https://flask.palletsprojects.com/en/1.1.x/quickstart/

I can't really help you with the import error as I do not use Pylance, but I would bet that you have multiple interpreters, so you should check that.
(Oct-01-2020, 08:02 PM)mlieqo Wrote: [ -> ]Well you are redirecting from index to contacts endpoint, but I don't see the contacts endpoint defined anywhere

contacts.html is located in the templates folder within the web subfolder