[英]Python BASE_DIR is not defined
I am trying to run a module called local_settings-example.py
which i got from here . 我正在尝试运行一个从此处获取的名为
local_settings-example.py
的模块。
The module is on the C:\\Python27\\pysec-master
file and it is given below 该模块位于
C:\\Python27\\pysec-master
文件中,如下所示
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)
? 并且最重要的是
BASE_DIR
可以在同一file(C:\\Python27\\pysec-master)
另一个模块中给出file(C:\\Python27\\pysec-master)
?
You need to define a variable called BASE_DIR
. 您需要定义一个名为
BASE_DIR
的变量。 Simple- otherwise Python doesn't know what it is and you get that error. 很简单-否则Python不知道它是什么,您会收到该错误。 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
该文件:
import relevant_file
Then you would access it like this: 然后,您将像这样访问它:
relevant_fle.BASEDIR
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.