Python名称'os'未定义 [英] Python name 'os' is not defined

查看:1376
本文介绍了Python名称'os'未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从设置导入运行此python模块

  PROJECT_ROOT 

DEBUG = True
TEMPLATE_DEBUG = DEBUG


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


#使这个唯一,并且不要与任何人分享。
SECRET_KEY ='sdfgtardyure34654356435'

#Digang指向Django运行服务器使用的WSGI应用程序的路径;在v1.4中添加
WSGI_APPLICATION ='wsgi.application'

############### PYSEC特定变量

#假设此目录存在
DATA_DIR =%s / pysec / data /%PROJECT_ROOT

但每当我尝试按 F5 运行它时,我会得到这个

 回溯(最近一次调用最后一次):
文件C:\Python27 \ pysec-master \ local_settings-example.py,第11行,< module>
'NAME':os.path.join(BASE_DIR,'db_name.sqlite3'),
NameError:名称'os'未定义

该模块位于 C:\ Pyy27 \pysec-master 中,我得到了这里



您知道我必须做些什么才能成功运行模块?

解决方案

只需添加:

 在开头,之前:

$ b

 来自设置导入PROJECT_ROOT 

这将导入python的模块 os ,显然稍后会在模块的代码中使用而不会被导入。


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?

解决方案

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.

这篇关于Python名称'os'未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆