ImportError: No module named staticfilesregistration


#1

Hello.
Everytime I try to run my server, i get the following error:

Unhandled exception in thread started by <function wrapper at 0x10c6c80c8>
Traceback (most recent call last):
  File "/Users/Angel/projects/myhellowebapp/venv/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/Angel/projects/myhellowebapp/venv/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/Users/Angel/projects/myhellowebapp/venv/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "/Users/Angel/projects/myhellowebapp/venv/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/Angel/projects/myhellowebapp/venv/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/Angel/projects/myhellowebapp/venv/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/Users/Angel/projects/myhellowebapp/venv/lib/python2.7/site-packages/django/apps/config.py", line 123, in create
    import_module(entry)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named staticfilesregistration

I’m not sure what’s going on here. I have installed django-registration-redux-1.3, and I’m running in my Virtual Environment. This is the chapter “Adding a Registration Page” from the book.


#2

That’s weird, there shouldn’t be anything named this in your project. Is there a type somewhere where you import “staticfiles” in the templates, maybe registration was accidentally pasted in?


#3

In the chapter under the heading “Add links to nav to login and logout”, users are told to update base.html that has the load staticfiles up top.

{% load staticfiles %}
<!doctype html>
<html>
    <head>
        <title>
            {% block title %}
                My Hello Web App Project
            {% endblock %}
        </title>
        <link rel="stylesheet" href="{% static 'css/style.css' %}" />
        {% block header %}{% endblock %}
    </head>
    <body>
        <header>
            <h1>Hello Web App</h1>
            <nav>
                <ul>
                    <li><a href="{% url 'home' %}">Home</a></li>
                    <li><a href="{% url 'about' %}">About</a></li>
                    <li><a href="{% url 'contact' %}">Contact</a></li>
                    {% if user.is_authenticated %}
                    <li><a href="{% url 'auth_logout' %}">Logout</a></li>
                    {% else %}
                    <li><a href="{% url 'auth_login' %}">Login</a></li>
                    <li><a href="{% url 'registration_register' %}">Register</a></li>
                    {% endif %}
                </ul>
            </nav>
        </header>
        {% block content %}{% endblock %}
        {% block footer %} {% endblock %}
    </body>
</html>

That’s what mine looks like. Is that what you’re referring too?

Just for measure though, I’m going to share all the relevant files related to this chapter that were updated.

Settings.py

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 's(0d2_(y(@dru2556=x&mx7p#33c(=ry+@ak9g@l-+jue6f#rs'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'collection',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles'
    'registration',
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'hellowebapp.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'hellowebapp.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'

ACCOUNT_ACTIVATION_DAYS = 7
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
DEFAULT_FROM_EMAIL = '[email protected]'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
EMAIL_PORT = 1025

LOGIN_REDIRECT_URL = "home"

URLS.py

from django.conf.urls import url, patterns, include
from django.contrib import admin
from collection import views
from django.views.generic import TemplateView

urlpatterns = [
    url(r'^$',views.index, name='home'),
    url(r'^about/$', TemplateView.as_view(template_name='about.html'), name = 'about'),
    url(r'^contact/$', TemplateView.as_view(template_name='contact.html'), name = 'contact'),
    url(r'^things/(?P<slug>[-\w]+)/$', views.thing_detail, name = 'thing_detail'),
    url(r'^things/(?P<slug>[-\w]+)/edit/$', views.edit_thing, name = 'edit_thing'),
    url(r'^accounts/', include('registration.backends.simple.urls')),
    url(r'^admin/', include(admin.site.urls)),
]

And then there is the login, logout, registration complete, and registration form html pages that were created. If those are needed say the word and I shall share them.

Maybe you could see something in all that code that points to the problem?


#4

In your command line, can you search for the word “staticfilesregistration” within your project folder? http://askubuntu.com/questions/39200/how-to-search-for-files-containing-specific-word

The easiest would be probably grep, so you can run this in your command line:

projectfolder $ grep -R "staticfilesregistration"

Let me know if that finds any instances of that keyword in your files!


#5

Hello

I had to run:

project $ grep -R "staticfilesregistration" myhellowebapp

To get it to work. But I found one match. it was in my settings.py file. I went in and searched for it. While staticfilesregistration was not there, staticfiles was, with registration in the next line under installed_apps. Apparently, I forgot to put in a comma after staticfiles.

GAH! There’s always a comma missing, or an extra space somewhere that cause things to not work.

Either way, I have found the issue, fixed it, and now it works. Thank you!


#6

Yay, glad I could help!