OWADVL
OWADVL

Reputation: 11154

IntelliJ doesn't want to import

The problem is that IntelliJ Studio 13 doesn't want to recognize an import. I have my code like this

a folder named "app". Inside it

__init__.py

from flask import Flask

app = Flask(__name__)

from app import views, models

views.py

from flask import render_template, request
from models import *
from app import *

@app.route('/')
@app.route('/index')
def index(): 
    return "123"

Now in views.py the "from app import *" is greyed as unused, and there's a red warning under @app with "unresolved reference "app".

Can anyone explain me why is this happening and what's the fix for this. Thanks in advance

Upvotes: 2

Views: 377

Answers (1)

Isaac
Isaac

Reputation: 9652

from app import * will import the package contents into the current namespace. So the route function from the app package will be imported into the current namespace. Callable as route().

import app will import the app package into the current namespace as an object named app. Callable as app.route()

Generally the use of from app import * is frowned upon unless you are certain it is what you want to do. from app import route would be preferred.

Upvotes: 2

Related Questions