期間收到錯誤這是項目 博客 遷移 模板 的博客我的目錄結構 初始化的.py admin.py models.py tests.py urls.py views.pyDjango的appliation模板渲染
**mysite**
__init__.py
settings.py
urls.py
wsgi.py
其中博客是爲應用程序目錄和mysite的爲TE項目目錄
這是我博客/ urls.py
from django.conf.urls import url
from . import views
urlpatterns=[
url(r'^$',views.post_list, name='post_list'),
url(r'^post/(?P<pk>[0-9]+)/$',views.post_detail, name='post_detail'),
]
這是博客/靜態/ post_list.py
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="{%static "css/blog.css"%}">
</head
<body>
<h1>Testings django project</h1>
{% for posts in post%}
<h4><a href="{% url "post_detail" pk=post.pk %}">Title:{{posts.title}}</a></h4>
<p>content:{{posts.text}}</p>
{% endfor %}
</body>
</html>
這是views.py
從django.shortcuts導入渲染,get_object_or_404 從.models導入後
這裏創建你的意見。
def post_list(request):
posts=Post.objects.all()
return render(request,'blog/post_list.html',{'post':posts})
def post_detail(request,pk):
posts=get_object_or_404(Post,pk=pk)
return render(request,'blog/post_detail.html',{'post':posts})
這裏是錯誤的下面
*Reverse for 'post_detail' with arguments '()' and keyword arguments '{u'pk': ''}' not found. 0 pattern(s) tried: []
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.8.3
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'post_detail' with arguments '()' and keyword arguments '{u'pk': ''}' not found. 0 pattern(s) tried: []
Exception Location: C:\Python27\lib\site-packages\django\core\urlresolvers.py in _reverse_with_prefix, line 496
Python Executable: C:\Python27\python.exe
Python Version: 2.7.9
Python Path:
['D:\\djangogirls',
'C:\\Windows\\system32\\python27.zip',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages']
Server time: Mon, 20 Jul 2015 22:26:29 +0545*
你的錯誤狀態有關反向的post_detail這意味着你試圖訪問的URL post_detail視圖使用反向功能。當您試圖訪問服務器尚未加載url的名稱的反向時,通常會發生此錯誤。因此,這個錯誤。 –
怎麼可能是什麼解決方案 –
這就是我已經進口申請博客的網址,從django.conf.urls主要項目設置urls.py導入包括URL 從django.contrib中導入管理 URL模式= [ url(r'^ admin /',include(admin.site.urls)), url(r'',include('blog.urls')), ] –