Jay Modi
Jay Modi

Reputation: 3331

no module named context_processors Import Exception in views.py file

I'm trying a build a login/logout application in django. This is my view.py file code:

from django.core.contex_processors import csrf
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.contrib import auth

def login(request):
    c = {}
    c.update(csrf(request))
    return render_to_response('login.html', c)

def auth_view():
    username = request.POST.get('username','')
    password = request.POST.get('password','')
    user = auth.authenticate(username = username, password=password)

    if user is not None:
        auth.login(request, user)
        return HttpResponseRedirect('/accounts/loggedin','')
    else:
        return HttpResponseRedirect('/accounts/invalid')

def loggedin(request):
    return render_to_response('loggedin.html', {'full_name': request.user.username})

def invalid_login(request):
    return render_to_response('invalid_login.html')

def logout(request):
    auth.logout(request)
    return render_to_response('logout.html')

and this is the error that throws when i run any url as below:

Request URL:    http://127.0.0.1:8000/accounts/login/
Django Version:     1.6.6
Exception Type:     ImportError
Exception Value:     No module named contex_processors
Exception Location: /home/mjrulesamrat/django_mj/django_test/django_test/views.py in <module>, line 1

And here is my settings.py file where i have added middleware related to csrf and authentication as well as in Installed_app.

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'article',
)

MIDDLEWARE_CLASSES = (
    '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',
)

so i shown settings.py, views.py and error on my browser. Please help. oh yes and i foeget to mention url.py file.. Here it is.

from django.conf.urls import patterns, include, url
from article.views import HelloTemplate
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'^articles/', include('article.urls')),
    # Examples:
    # url(r'^$', 'django_test.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
     url(r'^hello/$', 'article.views.hello'),
     url(r'^hello_template/$', 'article.views.hello_template'),
     url(r'^admin/', include(admin.site.urls)),
     url(r'^accounts/login', 'django_test.views.login'),
     url(r'^accounts/logout', 'django_test.views.logout'), 
     url(r'^accounts/auth', 'django_test.views.auth_view'),
     url(r'^accounts/loggedin', 'django_test.views.loggedin'),
     url(r'^accounts/invalid', 'django_test.views.invalid_login'),
 )

This looks fine..only error is in views.py file's line 1.

Upvotes: 0

Views: 3307

Answers (1)

michael
michael

Reputation: 682

You have a typo, it should be: from django.core.context_processors import csrf.

Upvotes: 2

Related Questions