私は弁護士を見直すためのフォームを持つテンプレートでCreateView(CBV)を使用しています。CreateViewのNoReverseMatch
私はテンプレートでURLルーティングを使用しようとすると、私はこのエラーを取得:
Exception Value: Reverse for 'lawyerreview_create' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['fathers/lawyers/(?P<lawyerreview_slug>[\\w-]+)/createreview/$']
私は、たとえば、このURLに逆転したいと思います:父/弁護士/弁護士名/ createreview。しかし、別のものを試して2日後、私はその目標に近づいていません。誰かが私が間違っていることを教えてもらえますか?私は答えを探しているだけではなく、ELI5がdjangoで適切にリンクしていることを謙虚に求めています。
モデル:
class Lawyer(models.Model):
name = models.CharField(max_length=100, default='')
lawyer_slug = models.SlugField(default='')
def __str__(self):
return self.name
class Review(models.Model):
lawyer = models.ForeignKey(Lawyer, null=True)
review_title = models.CharField(max_length=69, default='')
review_created = models.DateTimeField('Date of Review', auto_now_add=True)
user_name = models.CharField(max_length=100)
rating = models.IntegerField()
review_comment = models.TextField(default='')
review_slug = models.SlugField(default='')
views.py
from django.views.generic import ListView, DetailView
from django.views.generic import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy
from .models import Lawyer, Review
class LawyerDetail(DetailView):
model = Lawyer
template = 'lawyer_detail.html'
context_object_name = 'lawyers'
def get_object(self):
lawyer_slug = Lawyer.objects.get(
lawyer_slug=self.kwargs.get('lawyer_slug')
)
return lawyer_slug
def get_context_data(self, **kwargs):
context = super(LawyerDetail, self).get_context_data(**kwargs)
context['lawyer_review'] = self.object.review_set.all()
return context
class LawyerReviewCreate(CreateView):
model = Review
fields = ['lawyer', 'rating', 'dos', 'review_comment']
class LawyerReviewUpdate(UpdateView):
model = Review
fields = ['lawyer', 'rating', 'dos', 'review_comment']
class LawyerReviewDelete(DeleteView):
model = Review
success_url = reverse_lazy('lawyer_detail')
template.html(NoReverseMatchエラーを生成するセクション)
{% if lawyer_review %}
{% for review in lawyer_review %}
<div class="review_buttom_wrapper">
<button class="review_button" href="{% url 'lawyerreview_create' lawyer.lawyerreview_create %}">
<strong>Review</strong> {{ review.lawyer.name }}
</button>
</div>
urls.py
url(r'^lawyers/(?P<lawyer_slug>[\w-]+)/$', LawyerDetail.as_view(), name='lawyer_detail'),
url(r'^lawyers/(?P<lawyer_slug>[\w-]+)/createreview/$', LawyerReviewCreate.as_view(), name='lawyer_createreview'),
url(r'^lawyers/(?P<lawyer_slug>[\w-]+)/update/$', LawyerReviewUpdate.as_view(), name='lawyer_editreview'),
url(r'^lawyers/(?P<lawyer_slug>[\w-]+)/delete/$', LawyerReviewDelete.as_view(), name='lawyer_deletereview'),
wobbily_colのソリューションを使用した後に生成
エラー:
Exception Value: Reverse for 'lawyerreview_create' with arguments '()' and keyword arguments '{'lawyerreview_slug': ''}' not found. 0 pattern(s) tried: []
変更テンプレートへ:
<button class="review_button" href="{% url 'lawyerreview_create' review.lawyer.lawyer_slug %}">
今、このエラーを取得する:
Exception Value: Reverse for 'lawyerreview_create' with arguments '('michael-ferrin',)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
を弁護士の名前は今URLにアップ示しています。これに
編集テンプレート:
<a href="{% url 'lawyer_createreview' review.review_slug %}">
<button class="review_button">
<strong>Review</strong> {{ review.lawyer.name }}
</button>
</a>
正しくテンプレートをreview_formにリンクされています。
Exception Value: Reverse for 'lawyer_createreview' with arguments '()' and keyword arguments '{'review_slug': ''}' not found. 1 pattern(s) tried: ['fathers/lawyers/(?P<lawyer_slug>[\\w-]+)/createreview/$']
私は審査フォームに送ってくれたページに戻ってルーティングされるように期待していた。しかし、上の私は、このエラーを取得し、提出します。
' "{%のurl 'lawyerreview_create' lawyer.lawyerreview_createの%}" 内のパラメータ' 'lawyer.laywerreview_create'の値は何ですか? –
問題はおそらくurls.pyにありますが、そこには何がありますか? –