奇怪的错误Django1.9“runserver”命令在我的一个virtualenvs中不起作用

2024-06-03 10:43:03 发布

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

最近我的一个应用程序开始出现问题。它在运行命令“runserver”几次后启动,但现在它根本没有启动。在

wsgi.py

"""
WSGI config for iesc 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", "SIAV.settings")

application = get_wsgi_application()

管理.py

^{pr2}$

设置.py

# Django settings for SIAV project.

import os
import django 


from datetime import timedelta

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SETTINGS_PATH = os.path.dirname(os.path.dirname(__file__))

CRISPY_TEMPLATE_PACK = 'bootstrap3'

#def show_toolbar(request):
#    return True
#SHOW_TOOLBAR_CALLBACK = show_toolbar

#INTERNAL_IPS = ('127.0.0.1',)
#DEBUG_TOOLBAR_PATCH_SETTINGS = False

ALLOWED_HOSTS = ['*']
DEBUG = True

THUMBNAIL_DEBUG = True 
THUMBNAIL_PREFIX ='cache/'

DEFAULT_CHARSET = 'utf-8' 
FILE_CHARSET = 'utf-8' 

include_resource_uri = False

ADMINS = (
    ('Gustavo', 'gustavo@alluxi.mx'),
)

file_path = ('/var/www/ghost/content/data/ghost.db')
if not os.path.exists(file_path):
    file_path = 'ghost.db'

MANAGERS = ADMINS

DATABASES = {
    'default': {
         #'ENGINE': 'django.db.backends.postgresql_psycopg2',  # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'ENGINE': 'django.db.backends.mysql',
        #'ENGINE': 'tenant_schemas.postgresql_backend',
        'NAME': 'siavdb',                      # Or path to database file if using sqlite3.
        'USER': 'user',                      # Not used with sqlite3.
        'PASSWORD': 'XXX',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',
        'OPTIONS': {
            'init_command': 'SET sql_mode = ""',
        },
        },
     'sqlite': {
        'NAME': file_path,
        'ENGINE': 'django.db.backends.sqlite3',
        'USER': '',
        'PASSWORD': ''
    }   
}

'''
DATABASE_ROUTERS = (
    'tenant_schemas.routers.TenantSyncRouter',
)
'''

LANGUAGE_SESSION_KEY = 'es'

ROOT_URLCONF = '/'

# URL of the login page.
LOGIN_URL = '/accounts/login/'

# URL of the logout page.
LOGOUT_URL = '/logout/'

# URL to redirect after login
LOGIN_REDIRECT_URL = '/SIAV/captura/'


# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Monterrey'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'es'

gettext = lambda x: x

LANGUAGES = (
    ('es', gettext('Spanish')),
)

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

USE_THOUSAND_SEPARATOR = False

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = False

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
#STATIC_ROOT = 'C:/inetpub/wwwroot/static/'
STATIC_ROOT = "/Users/gustavo/SIAV/app/static_prod"
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
#STATIC_URL = 'http://alluxi:8000/'
#STATIC_URL = 'http://localhost:100/'
# Url para desarrollo
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    #'C:/inetpub/wwwroot/app/static'
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    #'dajaxice.finders.DajaxiceFinder',
    #'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = ''

MIDDLEWARE_CLASSES = (
    'django_hosts.middleware.HostsRequestMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django_hosts.middleware.HostsResponseMiddleware'
    #'tenant_schemas.middleware.TenantMiddleware',
    #'debug_toolbar.middleware.DebugToolbarMiddleware',
    #'django_pdb.middleware.PdbMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'SIAV.urls'


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(SETTINGS_PATH, 'templates'),],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.core.context_processors.debug',
                'django.core.context_processors.i18n',
                'django.core.context_processors.media',
                'django.core.context_processors.static',
                'django.core.context_processors.request',
                'django.contrib.messages.context_processors.messages',
                'app.views.processors.get_all_users', 
                'app.views.processors.get_chat_messages', 
                'app.views.processors.cantidades_en_proceso', 
            ],
        },
    },
]

ROOT_HOSTCONF = 'hosts'

DEFAULT_HOST = 'website'


# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'SIAV.wsgi.application'


INSTALLED_APPS = (
    # The Django sites framework is required
    'django.contrib.admin',
    'django.contrib.sites',
    'django.contrib.contenttypes',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'sorl.thumbnail',
    'tastypie',
    'dal',
    'dal_select2',
    'endless_pagination',
    'bootstrap3',
    'app',
    'contabilidad',
    'calendario',
    'websock',
    'crispy_forms',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    # `allauth` specific authentication methods, such as login by e-mail
    'allauth.account.auth_backends.AuthenticationBackend',
)

SITE_ID = 1

回溯如下:

(SIAV)MacBook-Pro-de-Gustavo:SIAV gustavo$ python manage.py runserver
Performing system checks...

sh: /Users/gustavo/.virtualenvs/SIAV/bin/scriptspip.exe: No such file or directory
/Users/gustavo/.virtualenvs/SIAV/bin/python: can't open file 'manage.py': [Errno 2] No such file or directory
/Users/gustavo/.virtualenvs/SIAV/bin/python: can't open file 'manage.py': [Errno 2] No such file or directory
System check identified no issues (0 silenced).
March 09, 2016 - 17:12:52
Django version 1.9.4, using settings 'SIAV.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 54, in execute
    super(Command, self).execute(*args, **options)
  File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 93, in handle
    self.run(**options)
  File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 102, in run
    autoreload.main(self.inner_run, None, options)
  File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/utils/autoreload.py", line 333, in main
    reloader(wrapped_main_func, args, kwargs)
  File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/utils/autoreload.py", line 299, in python_reloader
    reloader_thread()
  File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/utils/autoreload.py", line 275, in reloader_thread
    change = fn()
  File "/Users/gustavo/.virtualenvs/SIAV/lib/python2.7/site-packages/django/utils/autoreload.py", line 205, in code_changed
    stat = os.stat(filename)
OSError: [Errno 2] No such file or directory: 'manage.py'
(SIAV)MacBook-Pro-de-Gustavo:SIAV gustavo$ 

哪个python

(SIAV)MacBook-Pro-de-Gustavo:SIAV gustavo$ which python
/Users/gustavo/.virtualenvs/SIAV/bin/python

我不知道会出什么问题。在

编辑:

我已经试过了:

  • 再造管理.py从头开始归档。在
  • 用pip重新安装django。在
  • 重现虚拟世界。在

删除此行时错误消失:

url(r'^admin/', include(admin.site.urls)),

从我的网址.py,但这不是一个解决方案,因为需要在我的应用程序上使用管理员。在

编辑

这种行为似乎只有在使用django1.9时才会发生,django1.8可以完美地工作。我认为这个错误可能与一个失败的第三方应用程序有关。在


Tags: topathdjangoinpycoreosline