日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python的setting怎么找_python-DJANGO_SETTINGS_MODULE如何配置

發(fā)布時間:2025/3/21 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python的setting怎么找_python-DJANGO_SETTINGS_MODULE如何配置 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我正在使用Django 1.8和Python-3.4的項目中

我想安裝模型包,以在應(yīng)用程序中自動創(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',

)

我想在控制臺內(nèi)的django admin實用程序中看到與安裝的軟件包有關(guān)的可用命令,但是最后,我收到了有關(guān)環(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是這樣設(shè)置的:

在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()

最后,當(dāng)我嘗試啟動django服務(wù)器時,得到以下輸出:

(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

如何正確設(shè)置我的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編寫的.

標(biāo)簽:django-settings,python,django

來源: https://codeday.me/bug/20191120/2041025.html

總結(jié)

以上是生活随笔為你收集整理的python的setting怎么找_python-DJANGO_SETTINGS_MODULE如何配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。