-1

I have an app.py file and I want to call a variable in a config file located in the same folder.

I have already tried to import the file but it doesn't recognize it

This is my app.py file

def ldap_connect(data):
   try:
       server = ldap.initialize(app.config['IP_ldap'])

this is my config.py file (located in the same folder)

# coding=utf-8

####CONFIG LDAP####
IP_ldap = "ldap://127.0.0.1"
Oliv
  • 120
  • 1
  • 12
  • 1
    Possible duplicate of [Importing files from different folder](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder) – DjaouadNM Jun 14 '19 at 08:25

3 Answers3

0

You need to import the content of your file in app.py with :

from config import *

and then :

app.config['IP_ldap'] = IP_ldap
F Blanchet
  • 1,430
  • 3
  • 21
  • 32
0

A simple import will do the trick:

from config import IP_ldap

def ldap_connect(data):
   try:
       server = ldap.initialize(IP_ldap)
Silveris
  • 1,048
  • 13
  • 31
0
from config.py import IP_ldap

if it does't work,

maybe you need add file init.py

zy li
  • 11
  • 2