クイズを取ろうとするとエラーが発生します。私のページの属性エラーはin this topicと同じですが、解決策は私の問題を解決していません。Djangoクイズアプリ:属性エラー
上記のトピックで説明した解決策を試しましたが、問題は解決していません。私はそのDjango Quizのすべてのアプリケーションを1つに混ぜて、同じファイル内にモデルを持っています。その時点では正常に機能しており、問題なく「管理者」ページの設定を管理することができました。
問題がクイズを撮影するときに依存している、私はこのトレースバックを受け取る:
Internal Server Error: /myquiz/take/
Traceback (most recent call last):
File "C:\P4\myapp\models.py", line 359, in user_sitting
sitting = self.get(user=user, quiz=quiz, complete=False)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\db\models\manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\db\models\query.py", line 387, in get
self.model._meta.object_name
myapp.models.DoesNotExist: Sitting matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\core\handlers\base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\core\handlers\base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\views\generic\base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "C:\P4\myapp\views.py", line 163, in dispatch
self.quiz)
File "C:\P4\myapp\models.py", line 361, in user_sitting
sitting = self.new_sitting(user, quiz)
File "C:\P4\myapp\models.py", line 339, in new_sitting
questions = ",".join(map(str, questions_set)) + ","
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\db\models\query.py", line 258, in __iter__
self._fetch_all()
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\db\models\query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "C:\Python\lib\site-packages\model_utils\managers.py", line 80, in iterator
sub_obj = self._get_sub_obj_recurse(obj, s)
File "C:\Python\lib\site-packages\model_utils\managers.py", line 153, in _get_sub_obj_recurse
node = getattr(obj, rel)
AttributeError: 'int' object has no attribute 'essay_question'
問題がessay_questionモデルやモデルのお座りにあるかもしれないように思え。しかし、私はこの問題の答えを見つけることができません。ここにエラーと関連していると思われるコードがありますが、もっと必要な場合は(ほとんどの部分はDjangoのQuizアプリケーションと同じです)。
座りマネージャモデル:
class SittingManager(models.Manager):
def new_sitting(self, user, quiz):
if quiz.random_order is True:
questions_set = quiz.questions_set.all() \
.select_subclasses() \
.order_by('?')
else:
questions_set = quiz.questions_set.all() \
.select_subclasses()
questions_set = questions_set.values_list('id', flat=True)
if questions_set.count() == 0:
raise ImproperlyConfigured('Question set of the quiz is empty. '
'Please configure questions properly')
if quiz.max_questions and quiz.max_questions < questions_set.count():
questions_set = questions_set[:quiz.max_questions]
questions = ",".join(map(str, questions_set)) + ","
new_sitting = self.create(user=user,
quiz=quiz,
question_order=questions,
question_list=questions,
incorrect_questions="",
current_score=0,
complete=False,
user_answers='{}')
return new_sitting
def user_sitting(self, user, quiz):
if quiz.single_attempt is True and self.filter(user=user,
quiz=quiz,
complete=True)\
.exists():
return False
try:
sitting = self.get(user=user, quiz=quiz, complete=False)
except Sitting.DoesNotExist:
sitting = self.new_sitting(user, quiz)
except Sitting.MultipleObjectsReturned:
sitting = self.filter(user=user, quiz=quiz, complete=False)[0]
return sitting
そしてQuizTakeビュー:EDITED
それは似た他の同じ溶液ではありませんので、私は答えをいただければ幸いです
このアプリでエラーが発生しました。もっと必要な情報を提供し、助けてくれてありがとう。
。
EDIT 2:ように見える私のviews.pyの
ここInternal Server Error: /myquiz/take/
Traceback (most recent call last):
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\core\handlers\base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\core\handlers\base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\views\generic\base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "C:\P4\myapp\views.py", line 171, in dispatch
return super(QuizTake, self).dispatch(request, *args, **kwargs)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\views\generic\base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\views\generic\edit.py", line 213, in get
return self.render_to_response(self.get_context_data())
File "C:\P4\myapp\views.py", line 206, in get_context_data
context = super(QuizTake, self).get_context_data(**kwargs)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\views\generic\edit.py", line 122, in get_context_data
kwargs['form'] = self.get_form()
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\views\generic\edit.py", line 35, in get_form_with_form_class
return get_form(self, form_class=form_class)
File "C:\P4\myapp\views.py", line 184, in get_form
return form_class(**self.get_form_kwargs())
TypeError: __init__() missing 1 required positional argument: 'question'
されている抽出物(:を取得しようとしているときに、私は今、これを取得してい
ビュー 'をmyquiz /取ります'
def dispatch(self, request, *args, **kwargs):
self.quiz = get_object_or_404(Quiz, url=self.kwargs['quiz_name'])
if self.quiz.draft and not request.user.has_perm('quiz.change_quiz'):
raise PermissionDenied
self.logged_in_user = self.request.user.is_authenticated()
if self.logged_in_user:
self.sitting = Sitting.objects.user_sitting(request.user,
self.quiz)
else:
self.sitting = self.anon_load_sitting()
if self.sitting is False:
return render(request, 'single_complete.html')
return super(QuizTake, self).dispatch(request, *args, **kwargs)
Get_form:
誤差)が生じることdef get_form(self, form_class):
if self.logged_in_user:
self.questions = self.sitting.get_first_questions()
self.progress = self.sitting.progress()
else:
self.questions = self.anon_next_questions()
self.progress = self.anon_sitting_progress()
if self.questions.__class__ is Essay_Questions:
form_class = EssayForm
return form_class(**self.get_form_kwargs())
def get_form_kwargs(self):
kwargs = super(QuizTake, self).get_form_kwargs()
return dict(kwargs, questions=self.questions)
FORM_VALIDとget_context_data
def form_valid(self, form):
if self.logged_in_user:
self.form_valid_user(form)
if self.sitting.get_first_questions() is False:
return self.final_result_user()
else:
self.form_valid_anon(form)
if not self.request.session[self.quiz.anon_q_list()]:
return self.final_result_anon()
self.request.POST = {}
return super(QuizTake, self).get(self, self.request)
def get_context_data(self, **kwargs):
context = super(QuizTake, self).get_context_data(**kwargs)
context['question'] = self.questions
context['quiz'] = self.quiz
if hasattr(self, 'previous'):
context['previous'] = self.previous
if hasattr(self, 'progress'):
context['progress'] = self.progress
return context
私はそれを理解できません。誰かが低い矢を拾って行くのではなく、私に教えてもらえますか? http://meta.stackoverflow.com/questions/253924/what-to-do-when-the-question-you-want-to-ask-is-a-duplicate?rq=1 – Jim