我已在Python Anywhere部署了我的网站,但它无效。我已经将它上传到python的任何地方,也改变了WSGI和settings.py,但它只是显示welcome page.。
服务器上的setting.py文件
# Django settings for website project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_db',
'USER': 'rahulsatal',
'PASSWORD': 'rahul',
'HOST': '',
'PORT': '',
}
}
'''
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
'''
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.3/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# 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.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
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
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = '/home/rahulsatal/website/media'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/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 = '/home/rahulsatal/website/static'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'
# 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.
)
# 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',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '-k$4lu9+wnz&nbnij!c8+f*ltoebjpn97^xu%ofra+)&5aa7vm'
# 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',
)
ROOT_URLCONF = 'website.urls'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'website',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
服务器上的WSGI文件
"""
WSGI config for website 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.7/howto/deployment/wsgi/
"""
import sys
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "website.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
DJANGO_SETTINGS_MODULE = 'website.website.settings'
sys.path.append('/home/rahulsatal/website')
# ...
DJANGO_SETTINGS_MODULE = 'website.settings'
,我的错误日志是 -
2015-02-26 22:02:05,989 :IOError: write error
2015-02-26 22:02:05,990 :RuntimeError: generator ignored GeneratorExit
2015-02-27 10:44:57,526 :/usr/lib/python2.7/threading.py:1160: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
2015-02-27 10:44:57,526 : return _active[_get_ident()]
2015-02-27 10:44:57,527 :Traceback (most recent call last):
2015-02-27 10:44:57,527 : File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2015-02-27 10:44:57,527 : self.error_log_file.logger.exception("Error running WSGI application")
2015-02-27 10:44:57,527 : File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-02-27 10:44:57,541 : self.error(msg, *args, **kwargs)
2015-02-27 10:44:57,541 : File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-02-27 10:44:57,541 : self._log(ERROR, msg, args, **kwargs)
2015-02-27 10:44:57,542 : File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-02-27 10:44:57,542 : record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-02-27 10:44:57,542 : File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-02-27 10:44:57,542 : rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-02-27 10:44:57,542 : File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-02-27 10:44:57,542 : self.threadName = threading.current_thread().name
2015-02-27 10:44:57,542 : File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-02-27 10:44:57,543 : return _active[_get_ident()]
2015-02-27 10:44:57,543 : File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2015-02-27 10:44:57,543 : app_iterator = self.app(environ, start_response)
2015-02-27 10:44:57,543 : File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 250, in __call__
2015-02-27 10:44:57,554 : self.load_middleware()
2015-02-27 10:44:57,554 : File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 39, in load_middleware
2015-02-27 10:44:57,562 : for middleware_path in settings.MIDDLEWARE_CLASSES:
2015-02-27 10:44:57,562 : File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 276, in __getattr__
2015-02-27 10:44:57,564 : self._setup()
2015-02-27 10:44:57,564 : File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
2015-02-27 10:44:57,616 : self._wrapped = Settings(settings_module)
2015-02-27 10:44:57,616 : File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 90, in __init__
2015-02-27 10:44:57,616 : mod = importlib.import_module(self.SETTINGS_MODULE)
2015-02-27 10:44:57,616 : File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
2015-02-27 10:44:57,617 : __import__(name)
2015-02-27 10:44:57,617 : File "./website/settings.py", line 33
2015-02-27 10:44:57,617 : ALLOWED_HOSTS = []
2015-02-27 10:44:57,617 : ^
2015-02-27 10:44:57,617 :SyntaxError: invalid syntax
2015-02-27 10:44:59,352 :Traceback (most recent call last):
2015-02-27 10:44:59,352 : File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2015-02-27 10:44:59,352 : self.error_log_file.logger.exception("Error running WSGI application")
2015-02-27 10:44:59,352 : File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-02-27 10:44:59,352 : self.error(msg, *args, **kwargs)
2015-02-27 10:44:59,352 : File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-02-27 10:44:59,352 : self._log(ERROR, msg, args, **kwargs)
2015-02-27 10:44:59,353 : File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-02-27 10:44:59,353 : record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-02-27 10:44:59,353 : File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-02-27 10:44:59,353 : rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-02-27 10:44:59,353 : File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-02-27 10:44:59,353 : self.threadName = threading.current_thread().name
2015-02-27 10:44:59,353 : File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-02-27 10:44:59,354 : return _active[_get_ident()]
2015-02-27 10:44:59,354 : File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2015-02-27 10:44:59,354 : app_iterator = self.app(environ, start_response)
2015-02-27 10:44:59,354 : File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 250, in __call__
2015-02-27 10:44:59,354 : self.load_middleware()
2015-02-27 10:44:59,354 : File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 39, in load_middleware
2015-02-27 10:44:59,354 : for middleware_path in settings.MIDDLEWARE_CLASSES:
2015-02-27 10:44:59,354 : File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 276, in __getattr__
2015-02-27 10:44:59,355 : self._setup()
2015-02-27 10:44:59,355 : File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
2015-02-27 10:44:59,355 : self._wrapped = Settings(settings_module)
2015-02-27 10:44:59,355 : File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 90, in __init__
2015-02-27 10:44:59,355 : mod = importlib.import_module(self.SETTINGS_MODULE)
2015-02-27 10:44:59,355 : File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
2015-02-27 10:44:59,355 : __import__(name)
2015-02-27 10:44:59,355 : File "./website/settings.py", line 33
2015-02-27 10:44:59,355 : ALLOWED_HOSTS = []
2015-02-27 10:44:59,355 : ^
2015-02-27 10:44:59,355 :SyntaxError: invalid syntax
请有人帮助我。
答案 0 :(得分:2)
我认为你发布的错误日志可能不适用,因为这样的错误意味着你会看到"出了问题"页。此外,我认为您的WSGI文件可能没问题(再次,因为您看到欢迎页面而不是错误页面)。您应该检查的是您正在运行您认为正在运行的代码。您WSGI文件所在的目录中的URL和视图是否指向您希望在那里看到的那些?
答案 1 :(得分:2)
1.Try:
/// <reference path = "__WScript.d.ts" />
ALLOWED_HOSTS = ['rahulsatal.pythonanywhere.com']
答案 2 :(得分:0)
在您的settings.py
中设置以下选项
ALLOWED_HOSTS=['*']
答案 3 :(得分:-2)
您需要将'localhost'
或'*'
添加到允许的主机中 - 否则任何人都无法访问您的网页。
ALLOWED_HOSTS = ('localhost')
希望这有帮助!