ViewDoesNotExist : Error
Asked Answered
C

2

0

I have the following code, as you can see there is a C_account() function in the view, but I'm still getting

**Exception Type: ViewDoesNotExist at /create_account/

Exception Value: Could not import EPM.views.C_account. View does not exist in module EPM.views.**

Any ideas what the problem might be?

The view (EPM/views.py) containing the C_account function definition:

from django.shortcuts import render_to_response
from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from EPM.forms import *
from EPM.models import *
from datetime import date
from django.contrib.sessions.models import Session
from django.conf.urls.defaults import *

from django.forms.formsets import formset_factory

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'deducive.settings'

from django.core.management import setup_environ
from deducive import settings
import csv


def C_account(request):
 if request.method == 'POST':
    form = CreateAccountForm(request.POST)
    if form.is_valid():

    acc_act_date = form.cleaned_data['Account_Activation_Date']
    present_date = date.today()
    if acc_act_date <= present_date:
        stat = 'active'
    else:
        stat = 'inactive'

    acc_cat_id = Account_Categories_T.objects.get(cat_name = stat, category = 'status')


        sto =   GL_Account_T(account_number=form.cleaned_data['Account_Number'],
                account_name=form.cleaned_data['Account_Name'],
                                account_description=form.cleaned_data['Account_Description'],
                                parent_account_number=form.cleaned_data['Parent_Account_Number'],
                                account_manager=form.cleaned_data['Account_Manager'],
                                account_category_id = acc_cat_id,
                                account_activation_date=form.cleaned_data['Account_Activation_Date'],
                                )
        sto.save()

        return HttpResponseRedirect('/create_account/thanks/')

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

def thanks(request):
    return render_to_response('Thanks.html')

and the URLConf (EPM/urls.py), which has the C_account view correctly hooked up to the create_account/ URL:

from django.conf.urls import patterns, include, url

urlpatterns = patterns('EPM.views',
    (r'^create_account/$', 'C_account'),
    (r'^create_account/thanks/$', 'thanks'),)
Colossus answered 9/7, 2012 at 10:29 Comment(5)
What is that file named that you've headed "view"? Where is it located?Kkt
its our views.py file its located inside the App named 'EPM'Colossus
And does that app have an __init__.py file?Kkt
Is the app in the INSTALLED_APPS entry in settings.py?Nasion
Also make sure you don't have any circular imports, i.e. nothing imported in this file, should import this itself. In particular check EPM/models.py and EPM/forms.pySigh
C
0

I cracked my error finally. problem was in my forms.py, I wrote CharField as Charfield at one place. but I am still wondering why was it pointing to the error in my forms.py I got it by importing my views.py in shell.

Colossus answered 10/7, 2012 at 13:51 Comment(0)
O
2

Glad to hear you've solved the issue.

The slightly confusing ViewDoesNotExist exception is probably because Django encountered an ImportError when reading views.py (which has from EPM.forms import *, which would have triggered an exception due to the field typo you mentioned); the current behaviour is to swallow many exceptions (such as ImportError) and re-raise them as ViewDoesNotExist exceptions.

There's a four-year-old Django bug discussing how to make these error messages more helpful (mainly by catching fewer exceptions). In the mean-time, you can track down these kinds of problems by trying e.g.

from EPM.views import *

in a shell (./manage.py shell), which will show you the original exception.

Ostensorium answered 10/7, 2012 at 16:12 Comment(0)
C
0

I cracked my error finally. problem was in my forms.py, I wrote CharField as Charfield at one place. but I am still wondering why was it pointing to the error in my forms.py I got it by importing my views.py in shell.

Colossus answered 10/7, 2012 at 13:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.