Python BASE_DIR没有被定义

2024-06-02 05:31:46 发布

您现在位置:Python中文网/ 问答频道 /正文

{{1}我从一个模块调用了{1}。在

该模块位于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

但是它总是给我奇怪的虫子。每当我试着运行它,它就会给我这个

^{pr2}$

我怎样才能解决这个问题?最重要的是BASE_DIR可以在同一个file(C:\Python27\pysec-master)的另一个模块中给出吗?在


Tags: 模块pathdebugimportmasterprojectdbbase
1条回答
网友
1楼 · 发布于 2024-06-02 05:31:46

您需要定义一个名为BASE_DIR的变量。简单-否则Python不知道它是什么,你就会得到这个错误。我不知道它应该是什么,所以我让你把它放进去。在

要从另一个模块访问该变量,您需要import该文件:

import relevant_file

然后您可以这样访问它:

^{pr2}$

相关问题 更多 >