【问题标题】:Django runserver not working after HerokuDjango runserver 在 Heroku 之后无法正常工作
【发布时间】:2016-03-05 07:53:53
【问题描述】:

我已在 Heroku 上成功发布了我的 Django Web 应用程序。但现在我想在我的本地主机上运行服务器。之前我可以使用“python manage.py runserver --insecure”,但现在我收到以下错误。

shashank@s-machine:~/development/hellowebapp/hellowebapp$ python manage.py runserver
/usr/local/lib/python2.7/dist-packages/django/contrib/sites/models.py:78: RemovedInDjango19Warning: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
  class Site(models.Model):

/usr/local/lib/python2.7/dist-packages/django/contrib/sites/models.py:78: RemovedInDjango19Warning: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
  class Site(models.Model):

Performing system checks...

System check identified some issues:

WARNINGS:
registration.RegistrationProfile.user: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
    HINT: ForeignKey(unique=True) is usually better served by a OneToOneField.

System check identified 1 issue (0 silenced).
March 05, 2016 - 07:47:35
Django version 1.8.4, using settings 'hellowebapp.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Unhandled exception in thread started by <function wrapper at 0x7f569e30b668>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 137, in inner_run
    handler = self.get_handler(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/runserver.py", line 24, in get_handler
    handler = super(Command, self).get_handler(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 55, in get_handler
    return get_internal_wsgi_application()
  File "/usr/local/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 60, in get_internal_wsgi_application
    sys.exc_info()[2])
  File "/usr/local/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 50, in get_internal_wsgi_application
    return import_string(app_path)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 26, in import_string
    module = import_module(module_path)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/shashank/development/hellowebapp/hellowebapp/hellowebapp/wsgi.py", line 13, in <module>
    from whitenoise.django import DjangoWhiteNoise
django.core.exceptions.ImproperlyConfigured: WSGI application 'hellowebapp.wsgi.application' could not be loaded; Error importing module: 'No module named whitenoise.django'

这是我的 WSGI.py

"""
WSGI config for hellowebapp 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
from whitenoise.django import DjangoWhiteNoise

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hellowebapp.settings_production")

application = get_wsgi_application()
application = DjangoWhiteNoise(application)

【问题讨论】:

  • 你看this了吗?

标签: python django heroku


【解决方案1】:

从转储的错误报告中,我很清楚您的问题来自缺少白噪声模块。从这里的最后一行>>

File "/home/shashank/development/hellowebapp/hellowebapp/hellowebapp/wsgi.py", 
line 13, in <module>
from whitenoise.django import DjangoWhiteNoise

django.core.exceptions.ImproperlyConfigured: WSGI application 
'hellowebapp.wsgi.application' could not be loaded; Error importing 
 module: 'No module named whitenoise.django'

第一建议:

  1. 确保您使用的 Virtualenv 处于活动状态,我假设您已经在该 virtualenv 中安装了 pypi 的 whitenoise 包。

【讨论】:

    猜你喜欢
    • 2022-06-25
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 2014-02-04
    • 2018-03-09
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多