ali73
ali73

Reputation: 415

Import variable from parent directory in python package

I'm a bit new to python and I'm trying to learn Flask.

My project structure looks like this:

project/
   __init__.py
   views/
       __init__.py
       profile.py

My project/__init__.py looks like this:

from flask import Flask
from views.profile import app
app = Flask(__name__)

I'm trying to import app from project/__init__.py intoprofile.py.

I've tried some ways that none of them worked.

Upvotes: 1

Views: 1721

Answers (1)

ali73
ali73

Reputation: 415

Finally I found an answer which works:

In my profile.py I put this:

import sys, os.path
sys.path.append(os.path.abspath('../'))
from ccs import app 

Upvotes: 2

Related Questions