gpt4 book ai didi

python - ViewDoesNotExist : Error

转载 作者:行者123 更新时间:2023-12-03 08:15:22 24 4
gpt4 key购买 nike

我有以下代码,如您所见, View 中有一个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.**

任何想法可能是什么问题?

包含 EPM/views.py函数定义的 View ( C_account):
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')

和URLConf( EPM/urls.py),它具有 C_account View 正确地连接到 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'),)

最佳答案

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

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

有一个四岁的Django bug讨论如何使这些错误消息更有帮助(主要是通过捕获更少的异常)。同时,您可以尝试通过以下方式找出此类问题:

from EPM.views import *

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

关于python - ViewDoesNotExist : Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11393257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com