我试图实现一个评级系统来接收用户提交的信息。但我只是想知道是否可以在一个模型文件中有两个类并获得Could not import myapp.comments.views.stars. View does not exist in module myapp.comments.views.
在我的模型文件中,我有
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()
顺便说一下,stars 是一个 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
已安装的应用程序:
('django.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')
Traceback:文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py”在get_response 101.request.path_info)文件“/Library/ Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py" 在解析 300. sub_match = pattern.resolve(new_path) File "/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) File "/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 中。结果 = func(*args) 文件“/Library/Frameworks/Python .framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py" 在 get_callable 101. (lookup_view, mod_name))
异常类型:ViewDoesNotExist at /rating/ 异常值:无法导入 myapp.comments.views.stars。模块 >myapp.comments.views 中不存在视图。`