python的setting怎么找_python-DJANGO_SETTINGS_MODULE如何配置
我正在使用Django 1.8和Python-3.4的項目中
我想安裝模型包,以在應用程序中自動創(chuàng)建數(shù)據(jù).
我已經(jīng)使用pip install django-mockups和easy_install django-mockups安裝了此軟件包.
我在我的settings.py文件的INSTALLED_APPS中添加了“ mockups”條目
INSTALLED_APPS = (
'suit',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mockups',
'tracks',
'albums',
'artists',
'userprofiles',
)
我想在控制臺內的django admin實用程序中看到與安裝的軟件包有關的可用命令,但是最后,我收到了有關環(huán)境變量DJANGO_SETTINGS_MODULE的注釋消息,而我無法在django-mockups軟件包中看到清單
(venv)? myproject django-admin help
Type 'django-admin help ' for help on a specific subcommand.
Available subcommands:
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
runfcgi
runserver
shell
showmigrations
sql
sqlall
sqlclear
sqlcustom
sqldropindexes
sqlflush
sqlindexes
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
syncdb
test
testserver
validate
Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).
(venv)?myproject
我檢查django-mockups軟件包是否已安裝,并檢查以下路徑目錄是否存在.
/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django_mockups-0.4.8.dist-info` and
/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups`
并安裝了django-mockups軟件包
(venv)? mockups pip freeze
Django==1.8.2
django-mockups==0.4.8
django-suit==0.2.13
Pillow==2.9.0
wheel==0.24.0
(venv)? mockups
我的DJANGO_SETTINGS_MODULE是這樣設置的:
在manage.py文件中
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sfotipy.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
并在wsgi.py中
"""
WSGI config for myproject project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
application = get_wsgi_application()
最后,當我嘗試啟動django服務器時,得到以下輸出:
(venv)? myproject ./manage.py runserver
/home/bgarcial/.virtualenvs/venv/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
return f(*args, **kwds)
Traceback (most recent call last):
File "./manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/django/apps/config.py", line 86, in create
module = import_module(entry)
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 2231, in _gcd_import
File "", line 2214, in _find_and_load
File "", line 2203, in _find_and_load_unlocked
File "", line 1200, in _load_unlocked
File "", line 1129, in _exec
File "", line 1448, in exec_module
File "", line 321, in _call_with_frames_removed
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups/__init__.py", line 2, in
from mockups.factory import Factory
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups/factory.py", line 1, in
from mockups import generators
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups/generators.py", line 100, in
class StringGenerator(Generator):
File "/home/bgarcial/.virtualenvs/venv/lib/python3.4/site-packages/mockups/generators.py", line 101, in StringGenerator
coerce_type = unicode
NameError: name 'unicode' is not defined
(venv)? myproject
如何正確設置我的DJANGO_SETTINGS_MODULE環(huán)境變量?
這是DJANGO_SETTINGS_MODULE配置,因此該模型不起作用嗎?
坦克很多:)
謝謝
解決方法:
我在github中找到了這個issue.
也許django-mockups不支持Python 3.
Python 3將unicode更改為str,將舊的str更改為字節(jié).
因此,如果您使用Python 3運行django-mockups.將引發(fā)NameError
如回溯所示,django-mockups是用Python 2編寫的.
標簽:django-settings,python,django
來源: https://codeday.me/bug/20191120/2041025.html
總結
以上是生活随笔為你收集整理的python的setting怎么找_python-DJANGO_SETTINGS_MODULE如何配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win7 nvme 支持补丁_Updat
- 下一篇: .exe已停止工作_【PS课堂】你的ph