Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ViewDoesNotExist:错误_Python_Django_View_Error Handling - Fatal编程技术网

Python ViewDoesNotExist:错误

Python ViewDoesNotExist:错误,python,django,view,error-handling,Python,Django,View,Error Handling,我有下面的代码,正如您所看到的,视图中有一个C_account()函数,但我仍然得到 **Exception Type: ViewDoesNotExist at /create_account/ Exception Value: Could not import EPM.views.C_account. View does not exist in module EPM.views.** 你知道问题出在哪里吗 包含C_账户功能定义的视图(EPM/views.py): from django.

我有下面的代码,正如您所看到的,视图中有一个
C_account()
函数,但我仍然得到

**Exception Type: ViewDoesNotExist at /create_account/

Exception Value: Could not import EPM.views.C_account. View does not exist in module EPM.views.**
你知道问题出在哪里吗

包含
C_账户
功能定义的视图(
EPM/views.py
):

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')

我终于破译了我的错误。 问题出在我的表格里。py,我在一个地方把CharField写成CharField。 但是我仍然想知道为什么它指向了我的
forms.py

我通过在shell中导入我的
视图.py来获得它。

很高兴听到您解决了这个问题

稍微令人困惑的
ViewDoesNotExist
异常可能是因为Django在读取
views.py
时遇到了一个
ImportError
(它从EPM.forms import*
中获得
,由于您提到的字段输入错误,它会触发异常);当前的行为是吞并许多异常(例如
importorror
),并将它们重新提升为
ViewDoesNotExist
异常

有一个四岁的孩子正在讨论如何使这些错误消息更有帮助(主要是通过捕获更少的异常)。同时,你可以通过尝试来追踪这类问题

从EPM.views导入*

在shell(
/manage.py shell
)中,将显示原始异常。

您标题为“查看”的文件名是什么?它位于何处?它是我们的views.py文件,它位于名为“EPM”的应用程序中,该应用程序是否有
\uuuuu init\uuuuuuuuupy
文件?该应用程序是否位于settings.py中的INSTALLED\u APPS条目中?还请确保没有任何循环导入,也就是说,在该文件中导入的任何内容都不会自行导入。特别检查
EPM/models.py
EPM/forms.py
from django.conf.urls import patterns, include, url

urlpatterns = patterns('EPM.views',
    (r'^create_account/$', 'C_account'),
    (r'^create_account/thanks/$', 'thanks'),)