我試圖實現一個評分系統,它接收用戶提交的信息。 但我只是想知道是否有可能在一個模型文件中的兩個班,並得到Could not import myapp.comments.views.stars. View does not exist in module myapp.comments.views.
向models.py添加一個類會導致「視圖不存在」錯誤?
在我的模型文件,我有
class CommentWithRating(Comment):
rating = models.IntegerField()
def save(self, *args, **kwargs):
self.content_object.rating.add(score=self.rating, user=self.user, ip_address=self.ip_address)
super(CommentWithRating, self).save(*args, **kwargs)
class Rating(models.Model):
first_name = models.charField(maxlength=30)
last_name = models.charField(maxlength=30)
department = models.charField(maxlength=30)
comment = models.charField(maxlength=10000)
communi_rating = models.IntegerField()
prepar_rating = models.IntegerField()
interact_rating = models.IntegerField()
help_rating = models.IntegerField()
順便說,明星是一個html文件。有任何想法嗎?
這是我的看法,
from django.shortcuts import render_to_response, render
from django.http import HttpResponse
from models import CommentWithRating
def stars(request):
return render(request, 'star.html', {'score': ''})
我的錯誤信息是根本,
無法導入myapp.comments.views.stars。查看模塊 myapp.comments.views中不存在。
我回溯是,
環境: 請求方法:GET
Django的版本:1.4
Python版本:2.7.2
安裝的應用程序:
('d jango.contrib.auth ' 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', ' django.contrib.staticfiles 」, '登記', 'django.contrib.admin', 'djangoratings') 安裝中間件: ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')
回溯: 文件「/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py」in get_response 101. request.path_info) 解析 300. sub_match = pattern.resolve(new_path) 文件「/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py」文件「 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py「解析 209. return ResolverMatch(self.callback,args,kwargs,self.name ) 回調中的文件「/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py」 216. self ._callback = get_callable(self._callback_str) 包裝中的文件「/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py」 27. result = func(* args) 文件「/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py」in get_callable 101。(lookup_view,mod_name))
異常類型:ViewDoesNotExist at/rating/ 異常值:無法導入myapp.comments.views.stars。查看不存在於模塊> myapp.comments.views.`中。
沒有,請將您的錯誤完整 – Efazati 2012-08-09 04:18:11
另外補充你的'的myapp /評論/ views.py'文件請的內容。 – 2012-08-09 05:49:19
評論文件夾中是否有__init__.py文件? – 2012-08-09 08:22:45