ImportError异常值:没有名为forms的模块

时间:2013-08-26 01:52:10

标签: python django

我在SO上经历了大部分类似的问题,到目前为止还没有找到一个帮我缩小范围。

我遇到了这个错误,但还没能解决。我最初不得不与一些文件进行斗争,以混合标签和空格。现在我已经摆脱了这个错误,我现在得到了这个错误,如果有人能指出我的方向会很好。

ImportError at /

No module named forms

Request Method:     GET
Request URL:    http://127.0.0.1:8000/
Django Version:     1.5.2
Exception Type:     ImportError
Exception Value:    

No module named forms

Exception Location:     /home/newssite/links/views.py in <module>, line 3
Python Executable:  /usr/bin/python
Python Version:     2.7.3
Python Path:    

['/home/chad/newssite',
'/usr/local/lib/python2.7/dist-packages/django_registration-1.0-py2.7.egg',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',     '/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
'/usr/lib/python2.7/dist-packages/ubuntuone-couch',
'/usr/lib/python2.7/dist-packages/ubuntuone-installer',
'/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']

Server time:    Sun, 25 Aug 2013 20:29:20 -0500

views.py文件

from django.views.generic import ListView, DetailView
from .models import Link, UserProfile
from .forms import UserProfileForm
from django.contrib.auth import get_user_model
from django.views.generic.edit import UpdateView
from django.core.urlresolvers import reverse

class LinkListView(ListView):
model = Link
queryset = Link.with_votes.all()
paginate_by = 5

class UserProfileDetailView(DetailView):
model = get_user_model()
slug_field = "username"
template_name = "user_detail.html"

def get_object(self, queryset=None):
    user = super(UserProfileDetailView, self).get_object(queryset)
    UserProfile.objects.get_or_create(user=user)
    return user
class UserProfileEditView(UpdateView):
model = UserProfile
form_class = UserProfileForm
template_name = "edit_profile.html"

def get_object(self, queryset=None):
    return UserProfile.objects.get_or_create(user=self.request.user)[0]

def get_success_url(self):
    return reverse("profile", kwargs={"slug": self.request.user})

1 个答案:

答案 0 :(得分:5)

检查异常值和位置:

Exception Type:     ImportError
Exception Value:    

No module named forms

Exception Location:     /home/chad/newssite/links/views.py in <module>, line 3

views.py的第3行尝试从forms.py导入,该forms.py应与views.py位于同一目录中。确保您的forms.py文件位于同一目录中,或者从实际存在的位置导入它。