尝试保存在django时找不到404页面

时间:2012-10-11 22:30:48

标签: django

任何人都可以帮我解决我的问题,在尝试保存我的页面时会出现错误404.这里是编码

urls.py

urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'^$', PatientView.as_view()),
(r'^patientList/$', PatientView.as_view(), name ="forside"),
(r'^rehab_diab/(?P<pk>\d+)/$', RehabDiabetesView.as_view(), name="rehabDiabetes_view"),

views.py

class RehabDiabetesView(UpdateView):
template_name="rehab_diab.html"
model = RehabDiabetes
form_class = RehabDiabetesForm

def get_context_data(self, **kwargs):
    context = super(RehabDiabetesView, self).get_context_data(**kwargs)
    context['pk']=self.kwargs['pk']
    return context

def get_object(self, queryset = None):
    try: 
        obj = RehabDiabetes.objects.get(owner = Patient.objects.get(id = self.kwargs['pk']))
    except: 
        obj = RehabDiabetes.objects.create(owner = Patient.objects.get(id = self.kwargs['pk']))
    return obj

def form_valid(self, form):
    form.save()
    return HttpResponseRedirect(reverse("forside"))

rehab_diab.html

<form id="content" action="rehabDiabetes_view pk" method="POST" style="opacity: 1; ">
{% csrf_token %}
<input type="submit" value="Gem" class="ui-button ui-widget ui-state-default ui-corner-all" />

-------#其余代码..

这是错误

Page not found (404)
Request Method: POST
Request URL:    http:xxx.xxx.xxx/rehab_diab/1/rehabDiabetes_view%20pk
Using the URLconf defined in rehab3.urls, Django tried these URL patterns, in this order:
^admin/
^$
^patientList/$ [name='forside']
^rehab_diab/(?P<pk>\d+)/$ [name='rehabDiabetes_view']
The current URL, rehab_diab/1/rehabDiabetes_view pk, didn't match any of these.

缺少什么链接?自从我在django的新手以来无法弄明白.. :( 提前谢谢你。

1 个答案:

答案 0 :(得分:0)

您的意思是action="{% url rehabDiabetes_view pk %}"吗?