Forums

crispy forms causes "No module named 'views'"

Hi,

I have a very strange error which pops up when inserting the crispy tag. Can anybody help?

    Django Version: 1.6.6
    Python Version: 3.3.2
    Installed Applications:
    ('django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'frontpage',
     'reg',
     'login',
     'reports',
     'crispy_forms')
    Installed Middleware:
    ('django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware')


    Template error:
    In template /home/dashcreator/dashboard/login/templates/login.html, error at line 19
       No module named 'views'
       9 :


       10 :


       11 : {% block login %}


       12 : <br>


       13 : <br>


       14 : <br>


       15 : <br>


       16 : <br>


       17 : <div class="container">


       18 :     <div class="row">


       19 :          {% crispy form form.helper %}


       20 :         {{ form }}


       21 :     </div>


       22 : </div>


       23 :


       24 : <br>


       25 : <br>


       26 : <br>


       27 : <br>


       28 : <br>


       29 :


    Traceback:
    File "/usr/local/lib/python3.3/dist-packages/django/core/handlers/base.py" in get_response
      112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/home/dashcreator/dashboard/login/views.py" in loginrequest
      37.         return render_to_response('login.html',context, context_instance = RequestContext(request))
    File "/usr/local/lib/python3.3/dist-packages/django/shortcuts/__init__.py" in render_to_response
      29.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
    File "/usr/local/lib/python3.3/dist-packages/django/template/loader.py" in render_to_string
      169.         return t.render(context_instance)
    File "/usr/local/lib/python3.3/dist-packages/django/template/base.py" in render
      140.             return self._render(context)
    File "/usr/local/lib/python3.3/dist-packages/django/template/base.py" in _render
      134.         return self.nodelist.render(context)
    File "/usr/local/lib/python3.3/dist-packages/django/template/base.py" in render
      840.                 bit = self.render_node(node, context)
    File "/usr/local/lib/python3.3/dist-packages/django/template/debug.py" in render_node
      78.             return node.render(context)
    File "/usr/local/lib/python3.3/dist-packages/django/template/loader_tags.py" in render
      123.         return compiled_parent._render(context)
    File "/usr/local/lib/python3.3/dist-packages/django/template/base.py" in _render
      134.         return self.nodelist.render(context)
    File "/usr/local/lib/python3.3/dist-packages/django/template/base.py" in render
      840.                 bit = self.render_node(node, context)
    File "/usr/local/lib/python3.3/dist-packages/django/template/debug.py" in render_node
      78.             return node.render(context)
    File "/usr/local/lib/python3.3/dist-packages/django/template/loader_tags.py" in render
      62.             result = block.nodelist.render(context)
    File "/usr/local/lib/python3.3/dist-packages/django/template/base.py" in render
      840.                 bit = self.render_node(node, context)
    File "/usr/local/lib/python3.3/dist-packages/django/template/debug.py" in render_node
      78.             return node.render(context)
    File "/home/dashcreator/.local/lib/python3.3/site-packages/crispy_forms/templatetags/crispy_forms_tags.py" in render
      207.         c = self.get_render(context)
    File "/home/dashcreator/.local/lib/python3.3/site-packages/crispy_forms/templatetags/crispy_forms_tags.py" in get_render
      119.         response_dict = self.get_response_dict(helper, context, is_formset)
    File "/home/dashcreator/.local/lib/python3.3/site-packages/crispy_forms/templatetags/crispy_forms_tags.py" in get_response_dict
      153.         attrs = helper.get_attributes(template_pack=self.template_pack)
    File "/home/dashcreator/.local/lib/python3.3/site-packages/crispy_forms/helper.py" in get_attributes
      358.         if self.form_action:
    File "/home/dashcreator/.local/lib/python3.3/site-packages/crispy_forms/helper.py" in get_form_action
      234.             return reverse(self._form_action)
    File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py" in reverse
      536.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
    File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py" in _reverse_with_prefix
      403.             self._populate()
    File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py" in _populate
      290.                     for name in pattern.reverse_dict:
    File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py" in reverse_dict
      315.             self._populate()
    File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py" in _populate
      303.                 lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
    File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py" in callback
      230.         self._callback = get_callable(self._callback_str)
    File "/usr/local/lib/python3.3/dist-packages/django/utils/functional.py" in wrapper
      32.         result = func(*args)
    File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py" in get_callable
      97.             mod = import_module(mod_name)
    File "/usr/lib/python3.3/importlib/__init__.py" in import_module
      90.     return _bootstrap._gcd_import(name[level:], package, level)

    Exception Type: ImportError at /login/loginrequest/
    Exception Value: No module named 'views'

my views.py

        from django.shortcuts import render_to_response, render
    from django.http.response import HttpResponse, StreamingHttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect
    from django.contrib.auth import authenticate, login, logout
    from django.contrib.auth.decorators import login_required
    from django.core.context_processors import csrf
    from login.forms import LoginForm
    from django.template import RequestContext
    from django.contrib.auth.models import User




    def loginrequest(request):
        if request.user.is_authenticated():
            return HttpResponseRedirect('/index')
        if request.method == 'POST':
            form = LoginForm(request.POST)
            if form.is_valid():
                username = form.cleaned_data['username']
                password = form.cleaned_data['password']
                reg = authenticate(username=username, password=password)
                if reg is not None:
                    login(request, reg)
                    return HttpResponseRedirect('/index')
                else:
                    context = {'form':form}
                    return render_to_response('login.html',context, context_instance = RequestContext(request))
            else:
                context = {'form':form}
                #messages.error(request, "Please correct the errors below and resubmit.")
                return render_to_response('login.html',context, context_instance = RequestContext(request))

        else:
            form = LoginForm()
            context = {'form':form}
            return render_to_response('login.html',context, context_instance = RequestContext(request))

my forms.py

    class LoginForm(forms.Form):
        username = forms.CharField(
            label = "username",
            max_length = 80,
            required = True,
        )

        password = forms.CharField(
            label = "password",
            max_length = 80,
            required = True,
            widget = forms.PasswordInput(render_value = False)
        )


        def __init__(self, *args, **kwargs):
            super(LoginForm, self).__init__(*args, **kwargs)
            self.helper = FormHelper()
            self.helper.form_id = 'id-LoginForm'
            self.helper.form_class = 'blueForms'
            self.helper.form_method = 'POST'
            #self.helper.form_action = '/auth/'

            self.helper.add_input(Submit('submit', 'Submit'))

What do you get if you run python manage.py shell from a bash console in your web app's directory?

I get:

Python 2.7.5+ (default, Feb 27 2014, 19:37:08) 
Type "copyright", "credits" or "license" for more information.

IPython 2.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

Ah, sorry, I see you're running a web app with Python 3.3. Could you run python3.3 manage.py shell instead? Also, please give all of the output -- I think you're missing a bit from the end of that last one.

here with python3.3:

    /usr/local/lib/python3.3/dist-packages/django/db/backends/sqlite3/base.py:58: RuntimeWarning: SQLite received a naive datetime (2014-10-08 17:30:36.87347
    5) while time zone support is active.
      RuntimeWarning)

    Python 3.3.2+ (default, Feb 28 2014, 00:52:16) 
    Type "copyright", "credits" or "license" for more information.

    IPython 2.1.0 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.

    In [1]:

Thanks! That all looks OK.

So, here's an experiment -- could you edit your web app's WSGI file (there's a link on the "Web" tab) and replace the last two lines, which probably look something like this:

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

...with this instead:

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

same error

Hmm -- where are you seeing the error? I don't see anything in the error logs, and when I visit the site I get something that looks like it's working. Is there a specific URL on the site?

Yes indeed there the error log is empty I don't know why.

I see the error when I try to visit

http://www.dashboard.lu/login/loginrequest/

The error only appears when I put the crispy tag

 {% crispy form form.helper %}

If I put the Django form tag

 {{ form }}

Then I have no errors and I can see the form.

I found somebody with the same bug but no answers:

http://wefixbugs.com/blog/Django---No-module-named-views-32143.html#.VDV9yvl_tsM

I have the same error when I try to visit

http://www.dashboard.lu/admin/

I found the problem. I had some old

 from "app name" import views

in one of my urls.py files which gave the "no module named views".

That's good to hear -- thanks for letting us know!

Hi,

I have a working web project, which uses 'crispy_forms'. But I am getting an error saying "No module named crispy_forms".

I have done the following: 1) Installed crispy_forms the virtual environment using the command "pip install --user --upgrade django-crispy-forms" 2) Peformed makemigrations using the command "python manage.py makemigrations", which returned "No changes Detected" 3) Performed migrate operation using the command "python manage.py migrate", which returned the following: "Operations to perform: Apply all migrations: admin, contenttypes, newsletter, auth, sessions Running migrations: No migrations to apply."

I don't really understand the issue here, FYI,I can see here that, the new crispy_forms, is nor migrated.

Can you please advice me on how I should go forward to solve this issue?

Thank you! Aravind Harikumar (aravind.pythonanywhere.com)

I found the problem. There were 2 virtual environments which were created. The pip installation was made in the wrong one. Now it is working. Thanks :)