-1

Im pretty new to using flask and when trying to run my webapp I get the following error:

  File "C:\Users\\Desktop\Flask\\Project\__init__.py", line 24, in create_app
    from .models import User
  File "C:\Users\\Desktop\Flask\\Project\models.py", line 1, in <module>
    from db import db
  File "c:\users\\appdata\local\programs\python\python38-32\lib\site-packages\db\__init__.py", line 69
    print "var", var
          ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("var", var)?

This is my code:

from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask import Blueprint
from flask_jwt_extended import (
    JWTManager)

import jwt

db = SQLAlchemy()

def create_app(): 
    app = Flask(__name__)
    jwt = JWTManager(app)
    app.config['SECRET_KEY'] = 'altman'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.sqlite'
    app.config['JWT_COOKIE_CSRF_PROTECT'] = False
    app.config['JWT_TOKEN_LOCATION'] = ['cookies']
    app.config["JWT_ACCESS_COOKIE_NAME"] = "Info"

    db.init_app(app)

    from .models import User


    @login_manager.user_loader
    def load_user(user_id):
        return User.query.get(int(user_id))

    from .api import auth as auth_blueprint
    app.register_blueprint(auth_blueprint)

    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    return app

This is the code for init.py. When running the webapp I get the error listed above. However ive been searching and found no solution.There is no line 69 in init.py and no print. Please help me out. Ive been trying to find the error for this the past couple of days and found no help. If needed I cna provide more code. Thanks :)

wahman51
  • 21
  • 1
  • 2
  • Check this too: https://stackoverflow.com/questions/50670788/web-py-installation-error – IoaTzimas Oct 12 '20 at 10:11
  • Some how you've ended up with a module written for Python 2 being called by Python 3. How did you install `db`? – scotty3785 Oct 12 '20 at 10:11
  • Oh thats weird I just looked at flask tutorials and followed them. – wahman51 Oct 12 '20 at 10:13
  • The syntax `print "hello world"` is from Python 2. You are using Python 3 which the correct syntax would be `print("hello world")`. In your `models.py` file you are importing `db`: `from db import db`. The [db library](https://github.com/lgastako/db) is not Python 3 compatible. There is also no reason to use that outdated library. – Tin Nguyen Oct 12 '20 at 10:14
  • Okay thanks for the help. In most turoials I saw them use import db to import the database, – wahman51 Oct 12 '20 at 10:15
  • I have a feeling that you don't need a `db` library at all. The `db` object you use in your `models` module is most probably the same object as in your `__init__` module (`db = SQLAlchemy()`). So you should use it to create your models. To prevent circular dependency problem with `db` import try using the approach in [this answer](https://stackoverflow.com/a/51762852/6682517). – Sergey Shubin Oct 12 '20 at 11:04

1 Answers1

-2

The syntax print "hello world" is from Python 2. You are using Python 3 which the correct syntax would be print("hello world"). In your models.py file you are importing db: from db import db. The db library is not Python 3 compatible. There is also no reason to use that outdated library

colde
  • 3,192
  • 1
  • 15
  • 26
wahman51
  • 21
  • 1
  • 2