django视图不存在

时间:2013-01-22 18:59:22

标签: django django-views

我有一些有用的观点,但现在我添加了一个新视图,它不再有效,我不断收到错误ViewDoesNotExist

回溯:

  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 101.request.path_info)

  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve 300.sub_match = pattern.resolve(new_path)

  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve 
209. return ResolverMatch(self.callback, args, kwargs, self.name)

  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in callback  216. self._callback = get_callable(self._callback_str)

  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py" in wrapper 27.result = func(*args)

  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in get_callable 101.(lookup_view, mod_name))

  Exception Type: ViewDoesNotExist at /login/
  Exception Value: Could not import owners.views.login_request. View does not exist in module owners.views.

关于我可能做错的任何其他信息/指示都会有所帮助。

MyView的

def login_request(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/profile')

    elif request.method == 'POST':
        form = Loginform(request.POST)

        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            site_user = authenticate(username= username,password = password )

            if site_user is not None:
                login(request,site_user)
                return HttpResponseRedirect('/profile')
            else:
               return render_to_response('login.html',{'form':form},context_instance = RequestContext(request))
        else:
            return render_to_response('login.html',{'form':form},context_instance = RequestContext(request))

    else:
        '''user not subinting show loging form'''
        form = Loginform()
        context = {'form': form}
        return render_to_response('login.html',context,context_instance = RequestContext(request))

我的网址看起来像这样

(r'^login/$','owners.views.login_request'),

我有大约70个视图,而且所有这些视图都只有' /'作品

2 个答案:

答案 0 :(得分:0)

确保视图函数的名称与URL中传递的名称相同。否则,请传递视图功能和您的网址,是的所有网址文件:)

答案 1 :(得分:0)

问题在于导入时模型混淆了,因为他们从各处导入,所以我制作了一个管理所有东西的中央应用程序。