8
8
891099838382015-12-19 06:49:52
Flask
89109983838, 2015-12-19 06:49:52

Flask doesn't see *.py files?

Freebsd 10.1 python34

test project by structure
/1/
-- run.py
/1/app
----__init__.py
----views.py
----models.py

when starting ./run.py
in views. py on import:
from models import User
stumbles and throws: ImportError: No module named models

But if you move the models.py file to the project root /1/ it works as expected --- what's wrong?
(looked at habrahabr => Flask Mega-Tutorial.)!!!

################################################### #####
/1/run.py

from app import app
if __name__ == '__main__':
    app.run


/1/app/__init__.py
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)

from app import views, models


/1/app/views.py
from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash
from app import app, db
import os, sys
from models import User

@app.route('/')
def index():
    return render_template('index.html)

@app.route('/product/')
def product():
    return render_template('product.html)

app_dir = os.path.realpath(os.path.dirname(__file__))
database_path = os.path.join(app_dir, app.config['DATABASE_FILE'])
if not os.path.exists(database_path):
    db.create_all()


/1/app/models.py
from app import db

class User(db.Model):
    id = db.Column(db.Integer,primary_key = True)
    username = db.Column(db.String(64), unique = True, nullable=False, index = True)
    password = db.Column(db.String(64))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Savchuk, 2015-12-19
@89109983838

from .models import User
try like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question