Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dajaxice在本地运行,但django设置存在问题,无法使其在线工作_Django_Django Settings_Dajaxice - Fatal编程技术网

Dajaxice在本地运行,但django设置存在问题,无法使其在线工作

Dajaxice在本地运行,但django设置存在问题,无法使其在线工作,django,django-settings,dajaxice,Django,Django Settings,Dajaxice,我创建了一个Django帐户,它使用Dajaxice和Dajax 我在azure虚拟机中运行我的网站。当我使用localhost运行它时,Dajaxice/Dajax工作得非常好 然而,这在网上已经不起作用了。我的设置中有一些配置问题,但无法修复 在本地,Dajaxice/Dajax的指向方式如下: <script src="/static/dajaxice/dajaxice.core.js" type="text/javascript" charset="utf-8"></s

我创建了一个Django帐户,它使用Dajaxice和Dajax

我在azure虚拟机中运行我的网站。当我使用localhost运行它时,Dajaxice/Dajax工作得非常好

然而,这在网上已经不起作用了。我的设置中有一些配置问题,但无法修复

在本地,Dajaxice/Dajax的指向方式如下:

<script src="/static/dajaxice/dajaxice.core.js" type="text/javascript" charset="utf-8"></script>
我应该如何更改设置才能访问dajaxice online

这是迄今为止的my settings.py:

from os import path
PROJECT_ROOT = path.dirname(path.abspath(path.dirname(__file__)))

LOGIN_REDIRECT_URL = ''

HTMLFILES_DIR = 'C:\inetpub\wwwroot\chocolate\chocolate\chocolate\htmlFiles'

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    ('x', 'x@gmail.com'),
)

SESSION_EXPIRE_AT_BROWSER_CLOSE = True

TEMPLATE_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',
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'NAME': 'xx',
        'ENGINE': 'x',
        'HOST': 'x.x.x',
        'USER': 'x@zx',
        'PASSWORD': 'x!',
        'OPTIONS': {
            'provider': 'x'
        }
    }
}

TIME_ZONE = 'Europe/London'

LANGUAGE_CODE = 'en-us'

SITE_ID = 1

USE_I18N = True

USE_L10N = True

USE_TZ = True

MEDIA_ROOT = HTMLFILES_DIR + '\Pictures'

MEDIA_URL = 'http://localhost:1781/Pictures/'

STATIC_ROOT = ''

STATIC_URL = '/static/'

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.
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'dajaxice.finders.DajaxiceFinder',

)

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

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'chocolate.urls'

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

TEMPLATE_DIRS = (

   HTMLFILES_DIR
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'chocolate.chocolate',
    'dajaxice',
    'dajax',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin'
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)
EMAIL_HOST = 'smtp-mail.outlook.com'
EMAIL_HOST_USER = 'x@outlook.com'
EMAIL_HOST_PASSWORD = 'x'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'console':{
            'level':'INFO',
            'class':'logging.StreamHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        'dajaxice':{
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': True,
        },

    }
}

嗯,我找到了方法。对于任何在Django缺乏经验的人来说,这些信息可能会有所帮助

当我使用localhost时,拥有以下信息就可以了:

STATIC_ROOT = ''

STATIC_URL = '/static/'
但是,一旦计划部署应用程序,就需要在应用程序中的某个位置创建一个文件,并将路径包含在
STATIC\u ROOT
中。就我而言,情况如下:

STATIC_ROOT = 'C:/inetpub/wwwroot/chocolate/chocolate/chocolate/static/'
我手动创建了名为static的文件,您可以在上面看到。然后,添加在
STATIC\u URL
中创建的文件名

STATIC_URL = '/static/' 
然后,使用控制台访问应用程序的manage.py所在的文件。确保已将python添加为命令,并编写
python manage.py
。您的所有静态文件都将位于您创建的静态文件中。在我的例子中,dajaxice和dajax的文件在编写了
python manage.py collectstatic
之后出现在这个文件夹中

现在,dajaxice/dajax应该在部署后在线工作

STATIC_URL = '/static/'