Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reloader crashing #1274

Closed
uunsamp opened this issue Dec 10, 2014 · 2 comments
Closed

reloader crashing #1274

uunsamp opened this issue Dec 10, 2014 · 2 comments

Comments

@uunsamp
Copy link

uunsamp commented Dec 10, 2014

Hi, I seem to be running into a Flask specific issue, here are the details:

operating system:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:    14.04
Codename:   trusty

structure of package:

$ tree pantry
pantry
├── db.py
├── __init__.py
├── models
│   ├── food.py
│   └── __init__.py
└── run.py

The __init__.py files are empty.

error received:

$ pwd
/home/sam

$ python3.4 -m pantry.run
 * Running on http://127.0.0.1:5000/
 * Restarting with reloader
Traceback (most recent call last):
  File "/home/sam/pantry/run.py", line 2, in <module>
    from pantry.models.food import Food
ImportError: No module named 'pantry'

db.py:

from flask.ext.sqlalchemy import SQLAlchemy

db = SQLAlchemy()

food.py

from pantry.db import db

class Food(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True)
    amount = db.Column(db.Integer, unique=False)

    def __repr__(self):
        return '<Food %r>' % self.name

run.py

from flask import Flask, jsonify
from pantry.models.food import Food
from pantry.db import db
import json

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db.init_app(app)

@app.route('/food', methods=['GET'])
def list_food():
    items = []
    for food in Food.query.all():
        item = {
            "name": food.name,
            "amount": food.amount,
        }
        items.append(item)
    return jsonify(items)

if __name__ == '__main__':
    app.run(debug=True)
@untitaker
Copy link
Contributor

Duplicate of pallets/werkzeug#461

As a workaround, add /home/sam to sys.path.

@untitaker
Copy link
Contributor

Closing due to being a duplicate.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants