【问题标题】:Not able to create apps in Django无法在 Django 中创建应用程序
【发布时间】:2015-07-13 16:13:22
【问题描述】:

我正在尝试在我的 django 项目中创建应用程序。我在虚拟环境中遇到了这个错误。但是如果我尝试在没有虚拟环境的情况下创建应用程序,它可以正常工作

(venv)subhash@mordor:~/backend/backend$ django-admin startapp vehicles

Traceback (most recent call last):
File "/home/subhash/backend/venv/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/home/subhash/backend/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/subhash/backend/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/home/subhash/backend/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/subhash/backend/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/subhash/backend/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named backend.settings.dev

backend 是我的项目名称。

我的 dev.py 文件

from backend.settings.common import *

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = ['127.0.0.1']


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'django',                      
    'USER': 'tech',                   
    'PASSWORD': 'tech',              
    'HOST': 'localhost',                      
    'PORT': '5432',           
}
}

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

【问题讨论】:

  • 你的意思是settings.py还是dev.py
  • @Bun :有时人们使用单独的设置文件来保存他们的开发内容和他们的产品内容。这是很常见的做法
  • 我知道这一点,但错误提示为 No module named backend.settings.dev
  • 你能展示你的项目布局和manage.py的位置吗?

标签: python django frameworks


【解决方案1】:

尝试:

django-admin.py startapp vehicles

【讨论】:

    猜你喜欢
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    • 1970-01-01
    • 2018-01-11
    • 2013-05-09
    • 2021-04-22
    • 2016-02-01
    相关资源
    最近更新 更多