2016-08-18 21 views
1

私は、Amazon EC2のDjango認証と登録システムを使用して最も簡単なWebサイトを作成しようとしています。 Djangoのドキュメントやさまざまなウェブチュートリアルに従った後、私はまだ、このエラーが出る:Djangoの認証と登録

Page not found (404) Request Method: GET Request URL: http://52.43.72.141/polls/registration/?next=/polls/2/

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

^polls/ ^$ [name='index'] 
^polls/ ^(?P<pk>[0-9]+)/$ [name='detail'] 
^polls/ ^(?P<pk>[0-9]+)/results/$ [name='results'] 
^polls/ ^(?P<question_id>[0-9]+)/vote/$ [name='vote'] 
^polls/ ^login/$ [name='login'] 
^polls/^^login/$ [name='login'] 
^polls/^^logout/$ [name='logout'] 
^polls/^^password_change/$ [name='password_change'] 
^polls/^^password_change/done/$ [name='password_change_done'] 
^polls/^^password_reset/$ [name='password_reset'] 
^polls/^^password_reset/done/$ [name='password_reset_done'] 
^polls/^^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$ [name='password_reset_confirm'] 
^polls/^^reset/done/$ [name='password_reset_complete'] 
^admin/ 

The current URL, polls/registration/, didn't match any of these.

これは私が〜/ W /個人用サイト/ポーリング/ views.py

from django.shortcuts import get_object_or_404, render 
from django.http import HttpResponseRedirect 
from django.core.urlresolvers import reverse 
from django.views import generic 
from django.contrib.auth.mixins import LoginRequiredMixin 
from django.contrib.auth.decorators import login_required 
from .models import Choice, Question 

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.order_by('-pub_date')[:5] 

class DetailView(LoginRequiredMixin, generic.DetailView): 
    model = Question 
    template_name = 'polls/detail.html' 
    login_url = '/polls/registration/' 

class ResultsView(LoginRequiredMixin, generic.DetailView): 
    model = Question 
    template_name = 'polls/results.html' 

@login_required 
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/detail.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,))) 

にこれがどのような私できたものです〜/ w/mysite/polls/registration/login.htmlにあります。

{% extends "base.html" %} 

{% block content %} 

{% if form.errors %} 
<p>Your username and password didn't match. Please try again.</p> 
{% endif %} 

{% if next %} 
    {% if user.is_authenticated %} 
    <p>Your account doesn't have access to this page. To proceed, 
    please login with an account that has access.</p> 
    {% else %} 
    <p>Please login to see this page.</p> 
    {% endif %} 
{% endif %} 

<form method="post" action="{% url 'login' %}"> 
{% csrf_token %} 
<table> 
<tr> 
    <td>{{ form.username.label_tag }}</td> 
    <td>{{ form.username }}</td> 
</tr> 
<tr> 
    <td>{{ form.password.label_tag }}</td> 
    <td>{{ form.password }}</td> 
</tr> 
</table> 

<input type="submit" value="login" /> 
<input type="hidden" name="next" value="{{ next }}" /> 
</form> 

{# Assumes you setup the password_reset view in your URLconf #} 
<p><a href="{% url 'password_reset' %}">Lost password?</a></p> 

{% endblock %} 

DetailViewクラスが呼び出されたときにエラーが発生したようです。

誰かがこの作業を行う方法を明確にするのに役立つことができますか?ドキュメントから

+0

の両方を使用している私は、ディレクトリの世論調査でも同じlogin.htmlとを持っています/ pollls/templates /登録、投票/登録/テンプレート、投票/登録/テンプレート/登録 –

+0

エラーは、 '/ polls/registration'パターンと一致するURLを見つけることができず、それがeではないことを示しているxist。そのURLをurls.pyファイルに含めましたか? –

答えて

0

:私はあなたのコードから見ていることは、あなたのurls.py.で設定/ポーリング/登録していないということですhttps://docs.djangoproject.com/en/1.10/topics/auth/default/#topic-authorization

url('^', include('django.contrib.auth.urls')) 

あなたが追加する必要があります:

url('^registration/', views.WHATEVER_VIEW_YOU_WANT_USE) 

をあなたの投票結果の中から、今起こってDetailViewが使用されている場合ですいただきました

は は、それが行く

のurls.pyイムは、あなたのような何かをしたと仮定するとログインするが、URLにないので、それを見つけることができない。

またサイドノート、ドキュメントから

The LoginRequired mixin

When using class-based views, you can achieve the same behavior as with login_required by using the LoginRequiredMixin. This mixin should be at the leftmost position in the inheritance list.

ですから、ログインデコレータだけでなく、LoginRequired

+0

ありがとうございました。それが問題を解決しました。 –

関連する問題