简体   繁体   中英

Python BASE_DIR is not defined

I am trying to run a module called local_settings-example.py which i got from here .

The module is on the C:\\Python27\\pysec-master file and it is given below

import os

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

However it keeps giving me weird bugs . Whenever i try to run it, it gives me this

Traceback (most recent call last):
  File "<pyshell#10>", line 4, in <module>
    'NAME': os.path.join(BASE_DIR, 'db_name.sqlite3')
NameError: name 'BASE_DIR' is not defined

How can i work this problem around? And most important can the BASE_DIR be given in another module in the same file(C:\\Python27\\pysec-master) ?

You need to define a variable called BASE_DIR . Simple- otherwise Python doesn't know what it is and you get that error. I don't know what it should be, so I'll leave you to put that in.

To access that variable from another module, you would need to import that file:

import relevant_file

Then you would access it like this:

relevant_fle.BASEDIR

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM