Django + heroku - 导致错误在线不存在

时间:2016-01-07 12:25:31

标签: django heroku import django-registration

我是django的新手(使用python 2.7),我第一次尝试使用heroku但是我总是遇到以下错误:

remote: -----> Preparing static assets
remote:        Collectstatic configuration error. To debug, run:
remote:        $ heroku run python manage.py collectstatic --noinput

当我运行该命令时,会显示有关django registration redux库的导入错误。我之前在Django遇到过这个问题,我通过在'requests'下放置RequestSite和在'models'下放置Site来修复它。这解决了问题,但错误仍然出现在Heroku中。

(venv) C:\Users\Carolina\Desktop\Coding\venv\project1>heroku run python manage.p
    y collectstatic --noinput
    Running python manage.py collectstatic --noinput on acla-acla... up, run.3645
    Traceback (most recent call last):
      File "manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/_
    _init__.py", line 350, in execute_from_command_line
        utility.execute()
      File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/_
    _init__.py", line 324, in execute
        django.setup()
      File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", lin
    e 18, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/registry.py"
    , line 115, in populate
        app_config.ready()
      File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/app
    s.py", line 22, in ready
        self.module.autodiscover()
      File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/__i
    nit__.py", line 26, in autodiscover
        autodiscover_modules('admin', register_to=site)
      File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/module_load
    ing.py", line 50, in autodiscover_modules
        import_module('%s.%s' % (app_config.name, module_to_search))
      File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in im
    port_module
        __import__(name)
      File "/app/.heroku/python/lib/python2.7/site-packages/registration/admin.py",
    line 2, in <module>
        from django.contrib.sites.models import RequestSite
    ImportError: cannot import name RequestSite

事情是 - 那条线不存在。我去了venv / lib / site-packages / registration / admin.py,第2行就是这个:

from django.contrib import admin
from django.contrib.sites.requests import RequestSite    # HERE
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _

from registration.models import RegistrationProfile
from registration.users import UsernameField


class RegistrationAdmin(admin.ModelAdmin):
    actions = ['activate_users', 'resend_activation_email']
    list_display = ('user', 'activation_key_expired')
    raw_id_fields = ['user']
    search_fields = ('user__{0}'.format(UsernameField()), 'user__first_name', 'user__last_name')

    def activate_users(self, request, queryset):
        """
        Activates the selected users, if they are not already
        activated.

        """
        for profile in queryset:
            RegistrationProfile.objects.activate_user(profile.activation_key)
    activate_users.short_description = _("Activate users")

    def resend_activation_email(self, request, queryset):
        """
        Re-sends activation emails for the selected users.

        Note that this will *only* send activation emails for users
        who are eligible to activate; emails will not be sent to users
        whose activation keys have expired or who have already
        activated.

        """
        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)

        for profile in queryset:
            if not profile.activation_key_expired():
                profile.send_activation_email(site)
    resend_activation_email.short_description = _("Re-send activation emails")


admin.site.register(RegistrationProfile, RegistrationAdmin)

这是我用pip冻结得到的,以防万一:

Django==1.9
django-crispy-forms==1.5.2
django-registration==2.0.3
django-registration-redux==1.2
django-tinymce==2.2.0
Pillow==3.0.0
requests==2.9.0
South==1.0.2
stripe==1.27.1
wheel==0.24.0

有谁知道为什么会这样?提前谢谢!

编辑----

好的,问题是丹尼尔罗斯曼提到的问题。这个库在pypi中断了,我不得不告诉heroku从github安装它(包修复的地方)。 所以,我转到了我的requirements.txt文件并替换了这一行:

django-registration-redux==1.2

这一个:

-e git://github.com/macropin/django-registration.git#egg=django-registration==1.2 

(我还删除了'django-registration == 2.0.3',因为它是django-registration-redux的旧版本并且正在创建问题)。 希望这可以帮助人们解决同样的问题!

1 个答案:

答案 0 :(得分:0)

听起来您编辑了本地安装的django-registration-redux副本的代码。但这对Heroku没有任何影响,因为根据你的requirements.txt中的版本,库将直接从PyPI安装。

如果库真的坏了,你需要把它分叉并将你的requirements.txt指向你的固定版本。但是,看看GitHub上的代码,它实际上似乎并没有被打破;你只需要更新你指向的版本。