期间收到错误这是项目 博客 迁移 模板 的博客我的目录结构 初始化的.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')), ] –