S
S
Spoon in the brain2019-06-09 13:19:28
Python
Spoon in the brain, 2019-06-09 13:19:28

python-flask variable not being imported?

Good afternoon, there was a problem, I created a package, in __init__ I wrote

import telebot
from flask import Flask, session
from bot.db import *

app = Flask(__name__)
app.secret_key = 'ddddd'

if __name__ == '__main__':
  app.run(debug = True)

db.py looks like this
from flaskext.mysql import MySQL
from bot import app

app.config['MYSQL_DATABASE_USER'] = 'lie'
app.config['MYSQL_DATABASE_PASSWORD'] = 'zx23ww'
app.config['MYSQL_DATABASE_DB'] = 'telebot'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'

mysql = MySQL(app)
connect = mysql.connect()

And there was a problem, in db.py I can't import the app variable
* Serving Flask app "bot"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Usage: flask run [OPTIONS]

Error: While importing "bot", an ImportError was raised:

Traceback (most recent call last):
  File "/home/lietry/sova/callback/venv/lib/python3.6/site-packages/flask/cli.py", line 236, in locate_app
    __import__(module_name)
  File "/home/lietry/sova/callback/bot/__init__.py", line 3, in <module>
    from bot.db import *
  File "/home/lietry/sova/callback/bot/db.py", line 2, in <module>
    from bot import app
ImportError: cannot import name 'app'

So, what is the correct way to import variables from __init__.py?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Shitskov, 2019-06-09
@vessels

You import db from bot, and bot from db. Crossimports are not allowed. Either import one thing, or put all the variables for sharing in a separate package

A
alvvi, 2017-07-14
@alvvi

position: absolute for the text + position: relative for the parent to help you
and please post it on jsfiddle / codepen next time, it's hard to navigate by screenshots

P
Pavel Aydoom, 2017-07-14
@aydoom

https://jsfiddle.net/Aydoom/9j0sm34g/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question