79

I am trying to run this python module

from settings import PROJECT_ROOT

DEBUG = True
TEMPLATE_DEBUG = DEBUG


DATABASES = {
    'default': {
        'ENGINE':  'django.db.backends.sqlite3',
        'NAME' : os.path.join(BASE_DIR, 'db_name.sqlite3'),
    }
}


# Make this unique, and don't share it with anybody.
SECRET_KEY = 'sdfgtardyure34654356435'

# Python dotted path to the WSGI application used by Django's runserver; added in v1.4
WSGI_APPLICATION = 'wsgi.application'

############### PYSEC specific variables

# assumes this directory exists
DATA_DIR = "%s/pysec/data/" % PROJECT_ROOT

But whenever i try to run it by F5 i get this

Traceback (most recent call last):
  File "C:\Python27\pysec-master\local_settings-example.py", line 11, in <module>
    'NAME' : os.path.join(BASE_DIR, 'db_name.sqlite3'),
NameError: name 'os' is not defined

The module lives in the C:\Python27\pysec-master and i got pysec for here

Do you know what must i do to run the module with success?

smci
  • 32,567
  • 20
  • 113
  • 146
ExoticBirdsMerchant
  • 1,466
  • 8
  • 28
  • 53

2 Answers2

167

Just add:

import os

in the beginning, before:

from settings import PROJECT_ROOT

This will import the python's module os, which apparently is used later in the code of your module without being imported.

Ivaylo
  • 2,082
  • 1
  • 13
  • 13
34

The problem is that you forgot to import os. Add this line of code:

import os

And everything should be fine. Hope this helps!

Quintec
  • 1,064
  • 12
  • 22
  • I had a number of autokey python scripts that used `os` without importing it. They worked fine in Kubuntu 19.10 and earlier, but stopped working after upgrading to Kubuntu 20.04. `import os` fixed those scripts. Thank you! – Lonnie Best Apr 26 '20 at 08:20