Seite nicht gefunden (404) Anforderungsmethode: GET Anforderungs-URL: http://127.0.0.1:8000

Ich verfolgte die Django-Dokumentation und erstellte eine einfache Umfrage-App. Ich bin auf folgenden Fehler gestoßen:

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
    ^polls/
    ^admin/
The current URL, , didn't match any of these."

settings.py

ROOT_URLCONF = 'mysite.urls'

mysite / mysite / urls.py

from django.conf.urls import include,url
from django.contrib import admin
urlpatterns = [
    url(r'^polls/',include('polls.urls')),
    url(r'^admin/', admin.site.urls),]

mysite / polls / urls.py

from django.conf.urls import url

from . import views
app_name= 'polls' 
urlpatterns=[ 
    url(r'^

mysite / polls / views.py

from django.shortcuts import get_object_or_404,render
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from django.views import generic
from django.utils import timezone
from django.template import loader
from .models import Choice,Question
from django.template.loader import get_template
#def index(request):
#   return HttpResponse("Hello, world. You're at the polls index")
class IndexView(generic.ListView):
    template_name='polls/index.html'
    context_object_name='latest_question_list'
    def get_queryset(self):
        """Return the last five published questions."""
        return Question.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[5:]


class DetailView(generic.DetailView):
    model=Question
    template_name='polls/detail.html'
    def get_queryset(self):
        """
        Excludes any questions that aren't published yet.
        """
        return Question.objects.filter(pub_date__lte=timezone.now())
class ResultsView(generic.DetailView):
    model= Question
    template_name ='polls/results.html'

def vote(request, question_id):
    question=get_object_or_404(Question, pk=question_id)
    try:
        selected_choice= question.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        return render(request, 'polls/details.html',
            {
            'question':question,
            'error_message' : "You didn't select a choice" ,

            })  
    else:
        selected_choice.votes+=1
        selected_choice.save()
        return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))

index.html

<!DOCTYPE HTML >
{% load staticfiles %}
<html>
<body>
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />
{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="{% url 'polls:detail' question.id %}">{{question.question_test }}
    </a></li>
        {% endfor %}
        </ul>
    {% else %}
        <p>No polls are available.</p>
    {% endif %}
</body>
</html>

Dieser Linkhttp: //127.0.0.1: 8000 / polls / zeigt eine leere Seite mit 3 Aufzählungszeichen. (Ich habe 3 Fragen in meiner Datenbank und ihre IDs sind 5,6,7, weil ich die Fragen gelöscht und hinzugefügt habe.)

Mein Admin funktioniert gut!

Ich bin neu in Django und habe gesucht und nachgefragt und bin jetzt schon eine Weile dabei.

,views.IndexView.as_view(),name='index'), url(r'^(?P<pk>[0-9]+)/

mysite / polls / views.py

from django.shortcuts import get_object_or_404,render
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from django.views import generic
from django.utils import timezone
from django.template import loader
from .models import Choice,Question
from django.template.loader import get_template
#def index(request):
#   return HttpResponse("Hello, world. You're at the polls index")
class IndexView(generic.ListView):
    template_name='polls/index.html'
    context_object_name='latest_question_list'
    def get_queryset(self):
        """Return the last five published questions."""
        return Question.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[5:]


class DetailView(generic.DetailView):
    model=Question
    template_name='polls/detail.html'
    def get_queryset(self):
        """
        Excludes any questions that aren't published yet.
        """
        return Question.objects.filter(pub_date__lte=timezone.now())
class ResultsView(generic.DetailView):
    model= Question
    template_name ='polls/results.html'

def vote(request, question_id):
    question=get_object_or_404(Question, pk=question_id)
    try:
        selected_choice= question.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        return render(request, 'polls/details.html',
            {
            'question':question,
            'error_message' : "You didn't select a choice" ,

            })  
    else:
        selected_choice.votes+=1
        selected_choice.save()
        return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))

index.html

<!DOCTYPE HTML >
{% load staticfiles %}
<html>
<body>
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />
{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="{% url 'polls:detail' question.id %}">{{question.question_test }}
    </a></li>
        {% endfor %}
        </ul>
    {% else %}
        <p>No polls are available.</p>
    {% endif %}
</body>
</html>

Dieser Linkhttp: //127.0.0.1: 8000 / polls / zeigt eine leere Seite mit 3 Aufzählungszeichen. (Ich habe 3 Fragen in meiner Datenbank und ihre IDs sind 5,6,7, weil ich die Fragen gelöscht und hinzugefügt habe.)

Mein Admin funktioniert gut!

Ich bin neu in Django und habe gesucht und nachgefragt und bin jetzt schon eine Weile dabei.

,views.DetailView.as_view(), name='detail'), url(r'^(?P<pk>[0-9]+)/results/

mysite / polls / views.py

from django.shortcuts import get_object_or_404,render
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from django.views import generic
from django.utils import timezone
from django.template import loader
from .models import Choice,Question
from django.template.loader import get_template
#def index(request):
#   return HttpResponse("Hello, world. You're at the polls index")
class IndexView(generic.ListView):
    template_name='polls/index.html'
    context_object_name='latest_question_list'
    def get_queryset(self):
        """Return the last five published questions."""
        return Question.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[5:]


class DetailView(generic.DetailView):
    model=Question
    template_name='polls/detail.html'
    def get_queryset(self):
        """
        Excludes any questions that aren't published yet.
        """
        return Question.objects.filter(pub_date__lte=timezone.now())
class ResultsView(generic.DetailView):
    model= Question
    template_name ='polls/results.html'

def vote(request, question_id):
    question=get_object_or_404(Question, pk=question_id)
    try:
        selected_choice= question.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        return render(request, 'polls/details.html',
            {
            'question':question,
            'error_message' : "You didn't select a choice" ,

            })  
    else:
        selected_choice.votes+=1
        selected_choice.save()
        return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))

index.html

<!DOCTYPE HTML >
{% load staticfiles %}
<html>
<body>
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />
{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="{% url 'polls:detail' question.id %}">{{question.question_test }}
    </a></li>
        {% endfor %}
        </ul>
    {% else %}
        <p>No polls are available.</p>
    {% endif %}
</body>
</html>

Dieser Linkhttp: //127.0.0.1: 8000 / polls / zeigt eine leere Seite mit 3 Aufzählungszeichen. (Ich habe 3 Fragen in meiner Datenbank und ihre IDs sind 5,6,7, weil ich die Fragen gelöscht und hinzugefügt habe.)

Mein Admin funktioniert gut!

Ich bin neu in Django und habe gesucht und nachgefragt und bin jetzt schon eine Weile dabei.

,views.ResultsView.as_view(),name='results'), url(r'^(?P<question_id>[0-9]+)/vote/

mysite / polls / views.py

from django.shortcuts import get_object_or_404,render
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from django.views import generic
from django.utils import timezone
from django.template import loader
from .models import Choice,Question
from django.template.loader import get_template
#def index(request):
#   return HttpResponse("Hello, world. You're at the polls index")
class IndexView(generic.ListView):
    template_name='polls/index.html'
    context_object_name='latest_question_list'
    def get_queryset(self):
        """Return the last five published questions."""
        return Question.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[5:]


class DetailView(generic.DetailView):
    model=Question
    template_name='polls/detail.html'
    def get_queryset(self):
        """
        Excludes any questions that aren't published yet.
        """
        return Question.objects.filter(pub_date__lte=timezone.now())
class ResultsView(generic.DetailView):
    model= Question
    template_name ='polls/results.html'

def vote(request, question_id):
    question=get_object_or_404(Question, pk=question_id)
    try:
        selected_choice= question.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        return render(request, 'polls/details.html',
            {
            'question':question,
            'error_message' : "You didn't select a choice" ,

            })  
    else:
        selected_choice.votes+=1
        selected_choice.save()
        return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))

index.html

<!DOCTYPE HTML >
{% load staticfiles %}
<html>
<body>
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />
{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="{% url 'polls:detail' question.id %}">{{question.question_test }}
    </a></li>
        {% endfor %}
        </ul>
    {% else %}
        <p>No polls are available.</p>
    {% endif %}
</body>
</html>

Dieser Linkhttp: //127.0.0.1: 8000 / polls / zeigt eine leere Seite mit 3 Aufzählungszeichen. (Ich habe 3 Fragen in meiner Datenbank und ihre IDs sind 5,6,7, weil ich die Fragen gelöscht und hinzugefügt habe.)

Mein Admin funktioniert gut!

Ich bin neu in Django und habe gesucht und nachgefragt und bin jetzt schon eine Weile dabei.

,views.vote,name='vote'),]

mysite / polls / views.py

from django.shortcuts import get_object_or_404,render
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from django.views import generic
from django.utils import timezone
from django.template import loader
from .models import Choice,Question
from django.template.loader import get_template
#def index(request):
#   return HttpResponse("Hello, world. You're at the polls index")
class IndexView(generic.ListView):
    template_name='polls/index.html'
    context_object_name='latest_question_list'
    def get_queryset(self):
        """Return the last five published questions."""
        return Question.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[5:]


class DetailView(generic.DetailView):
    model=Question
    template_name='polls/detail.html'
    def get_queryset(self):
        """
        Excludes any questions that aren't published yet.
        """
        return Question.objects.filter(pub_date__lte=timezone.now())
class ResultsView(generic.DetailView):
    model= Question
    template_name ='polls/results.html'

def vote(request, question_id):
    question=get_object_or_404(Question, pk=question_id)
    try:
        selected_choice= question.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        return render(request, 'polls/details.html',
            {
            'question':question,
            'error_message' : "You didn't select a choice" ,

            })  
    else:
        selected_choice.votes+=1
        selected_choice.save()
        return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))

index.html

<!DOCTYPE HTML >
{% load staticfiles %}
<html>
<body>
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />
{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="{% url 'polls:detail' question.id %}">{{question.question_test }}
    </a></li>
        {% endfor %}
        </ul>
    {% else %}
        <p>No polls are available.</p>
    {% endif %}
</body>
</html>

Dieser Linkhttp: //127.0.0.1: 8000 / polls / zeigt eine leere Seite mit 3 Aufzählungszeichen. (Ich habe 3 Fragen in meiner Datenbank und ihre IDs sind 5,6,7, weil ich die Fragen gelöscht und hinzugefügt habe.)

Mein Admin funktioniert gut!

Ich bin neu in Django und habe gesucht und nachgefragt und bin jetzt schon eine Weile dabei.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage