フォームから投稿データを取得して表示したい。「{% url uasite1.views.sell_detail Sell_detail.pk %}」を使用して、pk に従ってデータを抽出しました。
しかし、[ NoReverseMatch ・・・, Reverse for 'uasite1.views.sell_detail' with arguments '('',)' and keyword arguments '{}' not found.] だけが表示されました。コードの何が問題になっていますか?
models.py
from django.db import models
from django.forms import ModelForm
class Sell(models.Model):
subject = models.CharField(max_length=100)
price = models.CharField(max_length=100)
condition = models.CharField(max_length=100)
email = models.EmailField()
body = models.CharField(max_length=200)
フォーム.py
from django.forms import ModelForm
from uasite1.models import Sell
class SellForm(ModelForm):
class Meta:
model = Sell
ビュー.py
from django.shortcuts import render_to_response,get_object_or_404
from django.http import HttpResponseRedirect
from uasite1.forms import SellForm
from uasite1.models import Sell
from django.template import RequestContext
def sell_detail(request, pk):
sell = get_object_or_404(Sell, pk=int(pk))
return render_to_response('sell_display.html',{'sell':sell})
def sell_create(request):
context = {}
if request.method == 'POST':
form = SellForm(request.POST)
if form.is_valid():
new_sell = form.save()
return HttpResponseRedirect('/sechand/%d/' % new_sell.pk)
else:
form = SellForm()
context['form'] = form
return render_to_response('sell.html',context,context_instance = RequestContext(request))
def Electronics(request):
latest_sell_list = Sell.objects.all()[:5]
return render_to_response('electronics.html',{'latest_sell_list':latest_sell_list})
urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^sechand/$','uasite1.views.sell_create'),
url(r'^sechand/(\d+)/$', 'uasite1.views.sell_detail'),
url(r'^electronics/$', 'uasite1.views.Electronics'),
url(r'^admin/', include(admin.site.urls)),
)
electronic.html
{% extends 'base.html' %}
{% block extrahead %}
<p><strong>Electronics</strong></p>
{% endblock %}
{% block content %}
<p><a href="{% url uasite1.views.sell_detail sell_detail.pk %}">{{ sell.subject }}</a></p>
{% endblock %}