前提・実現したいこと
djangoのチュートリアルを進めている最中です。
発生している問題・エラーメッセージ
チュートリアルの最中、ほとんど全てのコードに django.utils
のようなモジュールが出てきますが、これらを含むコードをrun scriptした際に、
ImportError: No module named django.utils
のようなエラーが出てきます。
ちなみに(今の所)、エラーが出ても問題なく動作しているように見えます
ただ、エラーを出し続けられるのも嫌なので、初歩的な質問で恐縮ですが、ご回答よろしくお願いします。
該当のソースコード
一例です
python
1from django.shortcuts import render,get_object_or_404 2from django.http import HttpResponse,HttpResponseRedirect 3from django.urls import reverse 4from django.views import generic 5 6from .models import Question,Choice 7 8class IndexView(generic.ListView): 9 template_name = 'polls/index.html' 10 context_object_name = 'latest_question_list' 11 12 13 def get_queryset(self): 14 """Return the last five published questions.""" 15 return Question.objects.order_by('-pub_date')[:5] 16 17 18class DetailView(generic.DetailView): 19 model = Question 20 template_name = 'polls/detail.html' 21 22 23class ResultsView(generic.DetailView): 24 model = Question 25 template_name = 'polls/results.html' 26 27def vote(request, question_id): 28 question = get_object_or_404(Question, pk=question_id) 29 try: 30 selected_choice = question.choice_set.get(pk=request.POST['choice']) 31 except (KeyError, Choice.DoesNotExist): 32 return render(request, 'polls/detail.html', { 33 'question': question, 34 'error_message': "You didn't select a choice.", 35 }) 36 else: 37 selected_choice.votes += 1 38 selected_choice.save() 39 return HttpResponseRedirect(reverse('polls:results', args=(question.id,))) 40 41def detail(request, question_id): 42 question = get_object_or_404(Question, pk=question_id) 43 return render(request, 'polls/detail.html', {'question': question})
ちなみにこれに対するエラーは、
Traceback (most recent call last): File "/Users/○○○/Documents/mysite/polls/views.py", line 2, in <module> from django.shortcuts import render,get_object_or_404 ImportError: No module named django.shortcuts [Finished in 0.076s]
です。順番を変えて試して見たところ、一番上のモジュールに対してエラーを出すみたいです
補足情報(FW/ツールのバージョンなど)
python 3.6.5
django 2.0.4

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/08 15:08
2018/05/08 23:35
2018/05/08 23:43
2018/05/10 05:18
2018/05/10 05:23