2016-07-02 175 views
0

我正在做這個簡單的公司評估應用程序,可能有詳細的意見。而列表視圖正常顯示,每當我點擊查看它的細節,我得到的頁面找不到(404)錯誤。它的工作原理在於,如果您要點擊某個部門(列表視圖),則必須將您帶到顯示徽標的詳細信息頁面以及該部門下的帖子。找不到頁面(404)

traceback;

Page not found (404) 
Request Method: GET 
Request URL: http://127.0.0.1:8000/1// 
Using the URLconf defined in Employee.urls, Django tried these URL patterns, in this order: 
^admin/ 
^appraisal/ 
^ ^$ [name='index'] 
^ ^(?P<pk>[0-9]+)/$ [name='detail'] 
^static\/(?P<path>.*)$ 
^media\/(?P<path>.*)$ 
The current URL, 1//, didn't match any of these. 

我的看法;

from django.views import generic 
from .models import Department 

class IndexView(generic.ListView): 
    template_name = "index.html" 
    context_object_name = "departments" 

    def get_queryset(self): 
     return Department.objects.all() 


class DetailView(generic.DetailView): 
    model = Department 
    template_name = "detail.html" 

我的網址;

項目/網址

from django.conf.urls import include, url 
from django.contrib import admin 
from django.conf import settings 
from django.conf.urls.static import static 

urlpatterns = [ 
    url(r'^admin/', include(admin.site.urls)), 
    url(r'^appraisal/', include('Appraisal.urls')), 
    url(r'^', include('Appraisal.urls')), 
] 
if settings.DEBUG: 
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) 
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 

應用/網址;

from django.conf.urls import url 
from . import views 

app_name = 'Appraisal' 

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

my models;

class Department(models.Model): 
    Name = models.CharField(max_length=30) 
    Leader = models.ForeignKey(Employee) 
    Department_logo = models.FileField() 
    is_favorite = models.BooleanField(default=False) 

    def __str__(self): 
     return '{}'.format(self.Name) 


class Post(models.Model): 
    Title = models.CharField(max_length=30) 
    Department = models.ForeignKey(Department, on_delete=models.CASCADE) 
    is_favorite = models.BooleanField(default=False) 

    def __str__(self): 
     return '{}'.format(self.Title) 

有人幫助我解決這個問題,我知道這是真的已經得到了這個工作不小的事。 謝謝!!

+0

您嘗試訪問的網址末尾有兩個斜線;那將不符合該模式。我們無法看到他們如何在沒有看到包含鏈接的模板的情況下到達那裏。 –

回答

0

你的鏈接是越野車http://127.0.0.1:8000/1//一個斜槓結束

太多它應該是http://127.0.0.1:8000/1/http://127.0.0.1:8000/對於網址正確匹配

你可能在模板錯誤鏈接建設。